我希望计算我的Range对象-Rng中的列数。 然后,我希望使用“选择大小写”操作来检查用户选择的列是否多于1个-如果是,则宏short中止。 我没有发现有关检查范围内列的nbr的任何信息。
下面的当前代码(我知道我需要chg:
MsgBox "Select a continuous range of cells where numeric values should be appended."
Set Rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8) 'Type Values, 8 - Range object
FirstRowRng = Rng.Row
LastRowRng = Rng.Row + Rng.Rows.Count - 1
MsgBox FirstRowRng & LastRowRng
MsgBox Range(Rng).Col.Count
Select Case Columns(Rng) 'Here I want my case to check nbr of col on Rng
Case 0:
MsgBox "Nothing selected." & vbCrLf & "ERROR! Macro aborted."
Case 1:
MsgBox "Selected range: "
'DO STUFF!!
Case Else
s = ""
For Each r In Selection.Areas
s = s + vbNewLine + r.Address(False, False)
Next r
MsgBox "Selected individual cells:" & s & vbCrLf & vbCrLf & "ERROR! Wrong selection - select a continuous range of cells where numeric values should be appended."
End Select
谢谢!
答案 0 :(得分:0)
代码中的关键字是 连续 。如果用户选择一个不错的单元格(矩形)或单个单元格,则:
rng.Columns.Count
将为您提供列数。但是,如果用户选择了一组不相交的单元格,则需要先检查rng.Areas.Count
,然后再检查每个Area
。