我正在准备宏以遍历一列中的多个单元格,并检查它们的值是否小于200(如果是),出现一个消息框以更改此类值。首先,我选择所有其他单元格都引用到的活动单元格(图像中显示了“起始范围”)。但是,此单元格是一个合并的单元格(2个合并的单元格)。如给定的MWE中所示。如果我在同一列中将活动单元格设置为2个合并单元格的形式,则在(对于下一个循环)中,如果其值小于100,则正确检查第一行(突出显示的黄色),但会跳过第二行进入第三行(绿色突出显示)。如果活动单元是单个单元而不是合并单元,则该过程可以正常工作。
Sub ss()
'Set active cell to which all offsets are related: On-screen selection
Worksheets("Sheet1").Activate
Dim column_name As Range
Set column_name = Application.InputBox(prompt:="Select the starting range(Column Name):", Title:="Starting range (Column Name)", Default:=Selection.Address, Type:=8)
column_name.Select
`Check Minimum value for the known dimension
Dim row_count As Single
For row_count = 0 To 1
If ActiveCell.Offset(row_count, 7).Value <= 200 Then
If MsgBox(prompt:="Known dimension is less than or equal to minimum dimension", Buttons:=vbYesNo, Title:="Modify Known Dimension") = vbYes Then
ActiveCell.Offset(row_count, 7).Value = InputBox("Enter New value:", "Modifying known dimension", ActiveCell.Offset(row_count, 7).Value)
End If
End If
Next row_count
End Sub