I am new to VBA and would greatly appreciate some assistance with this.
I have a spreadsheet that will take all the data in Sheet1, Column A and will copy the data into Sheet2.
The macro I currently have will transpose all the data from Sheet1:Column A to Sheet2 into 9 columns, then it will move down to the next row and will seperate the data into 9 columns until it reaches the end of the data in Sheet1:ColumnA.
This is a process that needs to be done every day, with new data being imported into Sheet1:ColumnA. Currently, I have to copy the data from Sheet2 into a master spreadsheet everyday because everytime I run the macro, It will overwrite the data in Sheet2 unless I import the data in Sheet1:ColumnA below the previous imported data each time.
I would like to be able to clear out the previous data each day in Sheet1:ColumnA, run the macro and append the results to Sheet2 in the next available empty row, instead of overwriting the data. I apologize if this is not clear and will provide clarification if necessary. Again, any help will be greatly appreciated.
Below is the Macro I am using. Please help me make the necessary changes to accomplish this.
Sub copyChunk()
' copy chunks of 9 cells from column A of sheet 1
' and paste their transpose on sheet 2
' starting in the first row
Dim sh1 As Worksheet, sh2 As Worksheet
Dim r1 As Range, r2 As Range
Dim chunk As Integer
chunk = 9
Set sh1 = ActiveWorkbook.Sheets("Import")
Set sh2 = ActiveWorkbook.Sheets("Results")
' picking the starting point here - this could be "anywhere"
Set r1 = Range(sh1.Cells(1, 1), sh1.Cells(chunk, 1))
Set r2 = sh2.[B2]
While Application.WorksheetFunction.CountA(r1) > 0
r1.Copy
r2.PasteSpecial Paste:=xlPasteAll, SkipBlanks:=True, Transpose:=True
' move down "chunk" cells for the source
Set r1 = r1.Offset(chunk, 0)
' move down one row for the destination
Set r2 = r2.Offset(1, 0)
lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lMaxRows + 1).Select
Wend
End Sub
I have a spreadsheet that will take all the data in Sheet1, Column A and will copy the data into Sheet2.
The macro I currently have will transpose all the data from Sheet1:Column A to Sheet2 into 9 columns, then it will move down to the next row and will seperate the data into 9 columns until it reaches the end of the data in Sheet1:ColumnA.
This is a process that needs to be done every day, with new data being imported into Sheet1:ColumnA. Currently, I have to copy the data from Sheet2 into a master spreadsheet everyday because everytime I run the macro, It will overwrite the data in Sheet2 unless I import the data in Sheet1:ColumnA below the previous imported data each time.
I would like to be able to clear out the previous data each day in Sheet1:ColumnA, run the macro and append the results to Sheet2 in the next available empty row, instead of overwriting the data. I apologize if this is not clear and will provide clarification if necessary. Again, any help will be greatly appreciated.
Below is the Macro I am using. Please help me make the necessary changes to accomplish this.
Sub copyChunk()
' copy chunks of 9 cells from column A of sheet 1
' and paste their transpose on sheet 2
' starting in the first row
Dim sh1 As Worksheet, sh2 As Worksheet
Dim r1 As Range, r2 As Range
Dim chunk As Integer
chunk = 9
Set sh1 = ActiveWorkbook.Sheets("Import")
Set sh2 = ActiveWorkbook.Sheets("Results")
' picking the starting point here - this could be "anywhere"
Set r1 = Range(sh1.Cells(1, 1), sh1.Cells(chunk, 1))
Set r2 = sh2.[B2]
While Application.WorksheetFunction.CountA(r1) > 0
r1.Copy
r2.PasteSpecial Paste:=xlPasteAll, SkipBlanks:=True, Transpose:=True
' move down "chunk" cells for the source
Set r1 = r1.Offset(chunk, 0)
' move down one row for the destination
Set r2 = r2.Offset(1, 0)
lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lMaxRows + 1).Select
Wend
End Sub