Excel VBA获得列的信
有没有一种方法可以只是将活动列作为文本返回到消息框中?
我有这个macros显示一个确认框,
Dim mycell mycell = ActiveCell.Address response = MsgBox("Are you sure you want to trim column " & mycell & "?", vbYesNo) If response = vbNo Then Exit Sub End If `code`
然而,我想问它“你确定要修剪F列”,例如,现在它将返回$ F $ 1格式的单元格。 我能得到列名吗?
您可以使用:
response = MsgBox("Are you sure you want to trim column " & Split(mycell, "$")(1) & "?", vbYesNo)
@Rory给出的解决scheme的另一种方法是用Mid(mycell, 2, 1)
2,1)replaceSplit(mycell, "$")(1)
Mid(mycell, 2, 1)
。
If ActiveCell.Column > 26 Then response = MsgBox("Are you sure you want to trim column " & Mid(mycell, 2, 2) & "?", vbYesNo) Else response = MsgBox("Are you sure you want to trim column " & Mid(mycell, 2, 1) & "?", vbYesNo) End If