Hello,
I am trying to combine several columns into one column, pasted on another sheet. I am getting an error of "Error 1004 Method 'Range' of object '_Worksheet' failed" when running my code. I am trying to use range.cells() so that I can reference columns in a for loop. At the top of each column from the copy sheet, I have a cell that has the numerical value for the last non blank cell in the column.
Sub Second_Round()
Dim targetworkbook As Workbook
Set targetworkbook = Application.ActiveWorkbook
Dim targetSheet As Worksheet
Set targetSheet = targetworkbook.Worksheets("Second Round Sample")
Dim copysheet As Worksheet
Set copysheet = targetworkbook.Worksheets("Second Round")
Dim pasterange As Range
Dim lastrowa As Integer
Application.Calculation = xlCalculationManual
Set pasterange = targetSheet.Range("A2")
For c = 2 To 50
lastrowa = copysheet.Cells(1, c).Value
copysheet.Range(Cells(3, c), Cells(lastrowa, c)).Copy
pasterange.PasteSpecial xlPasteValuesAndNumberFormats
pasterange = targetSheet.Range("A" & pasterange + lastrowa)
Next c
Application.Calculation = xlCalculationAutomatic
End Sub
I would appreciate any help.
I am trying to combine several columns into one column, pasted on another sheet. I am getting an error of "Error 1004 Method 'Range' of object '_Worksheet' failed" when running my code. I am trying to use range.cells() so that I can reference columns in a for loop. At the top of each column from the copy sheet, I have a cell that has the numerical value for the last non blank cell in the column.
Sub Second_Round()
Dim targetworkbook As Workbook
Set targetworkbook = Application.ActiveWorkbook
Dim targetSheet As Worksheet
Set targetSheet = targetworkbook.Worksheets("Second Round Sample")
Dim copysheet As Worksheet
Set copysheet = targetworkbook.Worksheets("Second Round")
Dim pasterange As Range
Dim lastrowa As Integer
Application.Calculation = xlCalculationManual
Set pasterange = targetSheet.Range("A2")
For c = 2 To 50
lastrowa = copysheet.Cells(1, c).Value
copysheet.Range(Cells(3, c), Cells(lastrowa, c)).Copy
pasterange.PasteSpecial xlPasteValuesAndNumberFormats
pasterange = targetSheet.Range("A" & pasterange + lastrowa)
Next c
Application.Calculation = xlCalculationAutomatic
End Sub
I would appreciate any help.