Hello!
I have a problem, I am completely green in programming and I need to write vba code which will copy data from one sheet to another. The problem, however, is that I have to copy the second column with a maximum of 17 tables (the number of tables and rows in the table varies depending on the demand) and then paste them to another sheet, but this time so that they are next to each other. And every time I get the error '1004' Method 'Range' of object '_Global' failed
Legend to code:
WN - A worksheet that specifies how many tables are to be created
WT - Worksheet with tables
WO - sheet to which the data will be copied
c + 14 - a space between the columns to be copied
d + 1 - column spacing after pasting
Below I am pasting my code along with an alternative attempt to do what I needed.
I have a problem, I am completely green in programming and I need to write vba code which will copy data from one sheet to another. The problem, however, is that I have to copy the second column with a maximum of 17 tables (the number of tables and rows in the table varies depending on the demand) and then paste them to another sheet, but this time so that they are next to each other. And every time I get the error '1004' Method 'Range' of object '_Global' failed
Legend to code:
WN - A worksheet that specifies how many tables are to be created
WT - Worksheet with tables
WO - sheet to which the data will be copied
c + 14 - a space between the columns to be copied
d + 1 - column spacing after pasting
Below I am pasting my code along with an alternative attempt to do what I needed.
VBA Code:
Dim wsl As Worksheet
Dim wsl1 As Worksheet
Dim i As Byte
i = Range("WN!A8").End(xlDown)
Set wsl = Worksheets("WT")
Set ws11 = Worksheets("WO")
c = 2 ' First column in source worksheet
d = 2 ' first column in destination worksheet
For e = 1 To i
Range(Cells(4, c), Cells(54, c)).Copy Destination:=Sheets("WO").Range(Cells(4, d))
d = d + 1
c = c + 14
'Range(.Cells(4, c), .Cells(54, c)).Copy Destination:=wsl1.Range("A5") 'wsl1.Range(.Cells(4, d + 1), .Cells(54, d + 1)) ' alternate solution
Debug.Print c, d
Next e