我需要获取范围的第一个非空白单元格的列字母。这个范围基本上是行的一部分。
示例:范围= A2:G2第一个非空白单元格位于F2单元格上。需要获取“ F”并将其存储在String变量中。最有效的方法是什么?
谢谢
尝试这个:
Sub columnName()
Dim mainRange As Range, cell As Range, columnName As String
Set mainRange = Range("A2:G2")
'Set mainRange = Selection
For Each cell In mainRange.Cells
If Not IsEmpty(cell.Value) Then
MsgBox Split(cell.Address, "$")(1)
Exit For
End If
Next cell
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句