列「M」の数値が変更されたときに、列「D」から「L」をマージするように右のコードを作成しようとしています。列Mの変更が変更された場合のマージ範囲
私は以下のコードを持っていますが、列 "M"の値にかかわらず、すべての行が下から上へ行2にマージされます。
私は何が欠けていますか?
Sub Merge_Upon_Change()
'Purpose: Merges cells between columns "D" and "L" when column "M" changes
Dim r As Long, i As Long
Application.DisplayAlerts = False 'Turn off windows warning popup
r = Cells(Rows.Count, "D").End(xlUp).row ' find last cell in Column D
For i = r To 2 Step -1
If Cells(i, 13).Value <> Cells(i + 13, 13).Value Then 'upon change in column M = 13
Range("D" & i & ":L" & i).Merge 'then merge column "D" through "L"
End If
Next i
Application.DisplayAlerts = True ''Turn on Windows warning popup
End Sub
おそらく 'Cells(i + 13、...'は 'Cells(i + 1、...'? –
コードを 'If Cells(i、13).Value <>セル(i + 1,13).Valueに変更するトリックを行いました。ありがとう!!ちなみに – XLmatters