我有这段代码来连接不同列的数据。但它没有给出任何结果,而我不知道问题是什么。
我想做的事情是:
Dim wb As Workbook
Dim ws1 As Worksheet
Set wb = ThisWorkbook
Set ws1 = ThisWorkbook.Sheets("Import")
Dim srcRng As Range, RowCnt As Long, ColCnt As Long
Set srcRng = ws1.Range("A2:AO152")
RowCnt = srcRng.Rows.Count
ColCnt = srcRng.Columns.Count
With ws1.Range("A" & Rows.Count).End(xlUp).Resize(RowCnt, ColCnt)
.Value = srcRng.Value
With .Columns(320) ' Col PN
' Apply formula to concate Col AJ,AK,AL,AM,AN,AO,AP
.FormulaR1C1 = "=RC[-394] & "","" & RC[-393] & RC[-392] & "","" & RC[-391] & "","" & RC[-390] & "","" & RC[-389] & ""-"" & RC[-388]"
' Convert formulas to values
.Formula = .Value
End With
End With
.Columns(430)
。获取 Col 索引Debug.Print Range("PN1").Column
Offset(1)
子句中缺少 With
。否则,源表的最后一行将被 .Value = srcRng.Value
覆盖。With ws1.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(RowCnt, ColCnt) ' **
.Value = srcRng.Value
With .Columns(430) ' Col PN **
' Apply formula to concate Col AJ,AK,AL,AM,AN,AO,AP
.FormulaR1C1 = "=RC[-394] & "","" & RC[-393] & RC[-392] & "","" & RC[-391] & "","" & RC[-390] & "","" & RC[-389] & ""-"" & RC[-388]"
' Convert formulas to values
.Formula = .Value
End With
End With