-1
我想获取特定工作表中包含特定字符串的第一个单元格的列地址。获取表示字符串第一个实例的单元格的列地址(VBA)
这里是代码,我已经写了这样做的:
Dim StringInQuestion As String
Dim ColumnRange1 As Range
NamedSheet.Select
Range("A1").Select
On Error Resume Next
Set FinalCell = Cells(1, 1).SpecialCells(xlLastCell)
FinalCellAddress = Cells(FinalCell.Row, FinalCell.Column).Address
Range(ColumnRange1).Select
Selection.Copy
Set ColumnRange1 = NamedSheet.Cells
Dim ColumnRange2 As Range
ColumnRange2 = ColumnRange1.Find(StringInQuestion)
Dim ColumnComposite As Variant
ColumnComposite = ColumnRange1.Address(ColumnAbsolute:=True)
Dim Column As Variant
'Format column address procured for further use (remove any numbers)
Dim intColumn As Integer
ColumnComposite = Trim(ColumnComposite)
For intColumn = 1 To Len(ColumnComposite)
If Not IsNumeric(Mid(ColumnComposite, intColumn, 1)) Then
Column = Column & Mid(ColumnComposite, intColumn, 1)
End If
Next intColumn
'Column = Column
尽管这段代码编译没有错误,“列”变量仍然是不确定的。有任何想法吗?请分享。谢谢!
更新:
谢谢@ScottHoltzman的帮助。
你只是想返回的第一次一定的字符串出现在列字母(或数字)工作表中的单元格? –
嗨@ScottHoltzman ---列字母。谢谢你的帮助。 – PBG
你的代码不工作吗?你会得到错误(如果是的话,什么错误和地点)? – BruceWayne