我目前正在将列名映射到 excel 中的变量,然后将公式中的变量用于新行,这是一个示例;
Dim posType as String
Cells.Find(What:="PositionType", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
posType = ActiveCell.EntireColumn.Address(False, False)
posType = Left(posType, InStr(1, posType, ":") - 1)
Sheets("sheet1").Range("A1").Select
ActiveCell.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
Selection.FormulaR1C1 = "PTH Size"
' PTH SIZE
Cells.Find(What:="PTH SIZE", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
Selection.Formula = _
"=IF(" & posType & "2=""PTH""," & settlementDateQuantity & "2,0)"
pthSize = ActiveCell.EntireColumn.Address(False, False)
pthSize = Left(pthSize, InStr(1, pthSize, ":") - 1)
r = ActiveCell.Row
With Worksheets("sheet1").Range(pthSize & r)
.AutoFill Destination:=Range(pthSize & r & ":" & pthSize & lastrow&)
End With
我导入的文件可以按其列的顺序每天更改,但它们使用相同的名称,目前我使用 find 方法获取列,然后将字母保存到字符串并使用我的公式中的引用使用查找和映射 100 列的过程非常缓慢......
我一直在尝试提出一种更好的方法来做到这一点,但想不出更快的方法,有人可以通过建议一种可能更快的方法来帮助我吗?
我也在考虑将我的项目转移到 EXCEL DNA,有人知道它会让我的宏运行多快吗?
谢谢