我正在尝试运行此宏,但由于我的 CSV 文件非常长而且我不想计算列号,有没有办法通过“DZ”等字母来引用该列?该代码工作正常,但我只需要引用这些深列并且不想计算它是哪个列号并且似乎无法找到显示列号的方法。我一直将“c”和“t”设置为列号,例如 1、2 等。
Sub ParseColumn
Dim sheet1 as Object
Dim sheet2 as Object
Dim r as long
Dim c as long
sheet1 = ThisComponent.Sheets.getbyname("Sheet1")
sheet2 = ThisComponent.Sheets.getbyname("Sheet2")
c = F
t = DZ
for r = 1 to 18739
copyFrom = sheet1.getCellByPosition(c,r)
copyTo = sheet2.getCellByPosition(t,r)
copyTo.String = copyFrom.String
next r
End Sub
更新 找到了解决方案:
Sub ParseColumn
Dim sheet1 as Object
Dim sheet2 as Object
Dim r as long
sheet1 = ThisComponent.Sheets.getbyname("Sheet1")
sheet2 = ThisComponent.Sheets.getbyname("Sheet2")
for r = 2 to 18739
copyFrom = sheet1.getCellRangeByName("AR" & r)
copyTo = sheet2.getCellRangeByName("S" & r)
copyTo.String = copyFrom.String
next r
End Sub