我的工作表
我已经开发了一些依赖于相同宏的工作表。它将查找标题,并从所选列中复制列。
该工作表是用来比较两组不同的数据,VBA 中的查找函数被经常使用。
我的问题
问题出现在 Find
函数中,因为它引用了同一列,但是有两个不同的名称,这些名称有轻微的比较。
它发生在两列中,这两列具有名称上的比较,如下所示:
Sub CopyPasteDataLookingForHeader()
Dim sht As Worksheet
Set sht = Sheets("Put in data")
'I'm trying to find the column header Total Lineamount within my sheet
FindTotalLineVAT = sht.Range("1:1").Find("Total Lineamount").Address(False, False, xlA1)
TotalLineVAT = Application.WorksheetFunction.Substitute(FindTotalLineVAT, 1, "")
'FindTotalLineVAT will return Cell "J1"
'TotalLineVAT will return column "J"
'I'm trying to find the column header Total Lineamount excl VAT within my sheet
FindTotalLineXVAT = sht.Range("1:1").Find("Total Lineamount excl VAT").Address(False, False, xlA1)
TotalLineXVAT = Application.WorksheetFunction.Substitute(FindTotalLineXVAT, 1, "")
'FindTotalLineXVAT will return Cell "J1"
'TotalLineXVAT will return column "J"
End Sub
我的目标
我希望这个公式可以返回单元格和列的两个不同结果。由于名称在某种程度上有所不同,因此“查找”函数应该返回两组不同的单元格。
有人可以解释为什么“查找”函数没有搜索整个名称,而只搜索其中一部分吗?
请告诉我,非常感谢您的答复 :)
LookAt
没有默认值为xlPart
,它只是使用在使用find
之前上次使用的选项。因此,如果您根本不指定LookAt
,您永远不会知道您将得到什么。 - Pᴇʜ