| 
    
     |  | 現在下記コードをユーザーフォーム上で利用しているのですが B列をたとえばD列あるいはG列というように[書式の都合で変更したい]
 ユーザーフォームにテキストボックスを置き簡単に列変更できませんか。?
 テキストボックスでいいのか悪いのかその辺もわかりません。
 ご指導お願いできますか。
 Option Explicit
 
 Private Sub CommandButton1_Click()
 With ActiveCell
 If .Column <> 2 Or .Value <> "" Then ※ここの2を変更 4or7
 MsgBox "セルの場所が不適切です"
 Exit Sub
 End If
 End With
 
 Dim i As Long
 Dim r As Long
 Dim myRes As Variant
 
 r = ActiveCell.Row
 
 myRes = MsgBox("小計を出します", vbYesNo)
 If myRes = vbYes Then
 For i = r - 1 To 1 Step -1
 If Cells(i, 1).Value = "小計" Or Cells(i, 1).Value = _
 "合計" Or Cells(i, 1).Value = "計" Then
 If i = r - 1 Then
 MsgBox ("計算する行がありません")
 Else
 Cells(r, 2).Value = "=sum(B" & i + 1 & ":B" & r - 1 & ")"
 Cells(r, 1).Value = "小計" ※2とBを変更 4or7 DorG
 End If
 i = 1
 End If
 Next
 End If
 End Sub
 
 
 Private Sub CommandButton2_Click()
 With ActiveCell
 If .Column <> 2 Or .Value <> "" Then ※ここの2を変更 4or7
 MsgBox "セルの場所が不適切です"
 Exit Sub
 End If
 End With
 
 Dim i As Long
 Dim r As Long
 Dim myRes As Variant
 
 r = ActiveCell.Row
 
 myRes = MsgBox("合計を出します", vbYesNo)
 
 For i = r - 1 To 1 Step -1
 If Cells(i, 1).Value = "合計" Or Cells(i, 1).Value = "計" Then
 If i = r - 1 Then
 MsgBox ("計算する行がありません")
 Else
 Cells(r, 2).Value = "=sumif(A" & i + 1 & ":B" & r - 1 & _
 ",""小計"",B" & i + 1 & ":B" & r - 1 & ")"
 Cells(r, 1).Value = "合計" ※2とBを変更 4or7 DorG
 End If
 i = 1
 End If
 Next
 End Sub
 
 
 |  |