有没有办法让活动列作为要在消息框中返回的文本?
我有一个显示确认框的宏
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格式返回单元格。我可以只获得列名吗?
答案 0 :(得分:2)
您可以使用:
response = MsgBox("Are you sure you want to trim column " & Split(mycell, "$")(1) & "?", vbYesNo)
答案 1 :(得分:1)
@Rory给出的解决方案的替代方案是将Split(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