0
myコードのFor Nextループは、何らかの理由で1行ずつ数値データの1行を一度に1行ずつコピーすることになっていますファイルは2回(i = 1およびi = 2の場合)、ソースデータの2番目の行(i = 3および4)で2回コピーされます。行番号変数は各ループごとに増分していきます。私はどのような援助のため、事前に間違って、もう一度感謝をやっている任意のアイデアExcel VBA - 次のループコピーで同じ行を複数回使用する場合
ます。Option Explicit
Sub CopyColumnTest()
Const FILE1 As String = "c:\users\john\documents\cvi - excel files\project - Cash Drawer Report\New Folder\PreFlashSales.xls"
Const FILE2 As String = "c:\users\john\documents\cvi - excel files\project - Cash Drawer Report\New Folder\2016 Flash Sales-JFP.xls"
Const Sheet1 As String = "Sheet1"
Const Sheet2 As String = "Actual"
Dim Col As Integer
Dim Col1 As Integer
Dim Col2 As Integer
Dim Col3 As Integer
Dim RowNum As Integer
Dim RowNum1 As Integer
Dim RowNum2 As Integer
Dim LastRow1 As Integer
Dim LastRow2 As Integer
Dim wb1 As Workbook, wb2 As Workbook
Dim i As Integer
i = 1
Col = 5
Col1 = 1
Col2 = 23
Col3 = 19
RowNum = 1
If wb1 Is Nothing Then Set wb1 = Workbooks.Open(FILE1)
If wb2 Is Nothing Then Set wb2 = Workbooks.Open(FILE2)
LastRow1 = wb1.Sheets(Sheet1).Cells(Rows.Count, "A").End(xlUp).row 'Last Row of Data in PreFlashSales Workbook
LastRow2 = wb2.Sheets(Sheet2).Cells(Rows.Count, "E").End(xlUp).row + 1 'Last Row of Data Previously Added in 2016 FlashSales-JFP
RowNum1 = LastRow2
With wb1.Sheets(Sheet1)
For i = 1 To LastRow1
*** wb2.Sheets(Sheet2).Range(wb2.Sheets(Sheet2).Cells(RowNum1, Col), wb2.Sheets(Sheet2).Cells(RowNum1, Col2)).Value = _
wb1.Sheets(Sheet1).Range(wb1.Sheets(Sheet1).Cells(RowNum, Col1), wb1.Sheets(Sheet1).Cells(RowNum & Col3)).Value ***
RowNum = RowNum + 1
RowNum1 = RowNum1 + 1
Next i
End With
End Sub
ご協力いただきありがとうございます。 – John
@Johnは正しいとマークしてください。答えのチェックマークをクリックします。それはあなただけができることです。 –
Scottありがとうございました! - 今私は大きな助けを認める方法を知っています – John