我有10年的数据,每年有4个季度。每个都有银行名称。我写了一个vba代码来复制所有数据,并将转置粘贴到工作簿末尾新创建的工作表中。代码运行正常。
然而,似乎只有那些以字母开头的银行" A"被复制了。其余的不是。我不明白为什么。
Sub Macro2()
Dim thiswb As Workbook, datawb As Workbook, ws As Worksheet
Dim datafolder As String
Dim cell As Range, datawblist As Range
Dim i As Long
Application.DisplayAlerts = False
Set thiswb = ThisWorkbook
i = 2
'Have the 40 file names in sheet2 of this workbook in cells A1:A40
Set datawblist = thiswb.Sheets("command").Range("A45:A61")
datafolder = "C:\Users\bryan\Desktop\Y4S1\Money and Banking\Empirical\QuarterSheets\2007q1\" 'change this to your directory they're in
For Each cell In datawblist
Set datawb = Workbooks.Open(Filename:=datafolder & cell & ".csv", ReadOnly:=True)
Set ws = thiswb.Sheets.Add(After:=thiswb.Worksheets(Worksheets.Count))
datawb.Sheets(1).UsedRange.Copy ws.Range("A1").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True
datawb.Close savechanges:=False
Next
End Sub