Excel VBA 将列作为字母
Excel VBA get column as letter
有没有办法在消息框中将活动列作为文本发送到 return?
我有这个显示确认框的宏,
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`
不过我想问 "Are you sure you want to trim column F" 例如,目前它将 return 格式为 $F$1 的单元格。我可以只获取列名称吗?
您可以使用:
response = MsgBox("Are you sure you want to trim column " & Split(mycell, "$")(1) & "?", vbYesNo)
@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
有没有办法在消息框中将活动列作为文本发送到 return?
我有这个显示确认框的宏,
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`
不过我想问 "Are you sure you want to trim column F" 例如,目前它将 return 格式为 $F$1 的单元格。我可以只获取列名称吗?
您可以使用:
response = MsgBox("Are you sure you want to trim column " & Split(mycell, "$")(1) & "?", vbYesNo)
@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