PDA

View Full Version : copy with loop double variable



michael32
08-17-2022, 06:20 AM
Hi,

could you please help me with copy from one sheets to another sheet in one workbook. I create this macro for it:
- I have here one problem if all variable from y is done than the variable z is running +2 e.g.:
....sheets("employees").cells(y "8",9).copy sheets("time_data_01").cells(2,4).offset(z "8",0)

....sheets("employees").cells(y "3",9).copy sheets("time_data_01").cells(2,4).offset(z "10",0)


Sub testing()
Dim y As Long
Dim z As Long
For z = 1 To 42
For y = 3 To 8
Sheets("employees").Cells(y, 9).Copy Sheets("Time_data_01").Cells(2, 4).Offset(z, 0)
z = z + 1
Next y, z
End Sub

p45cal
08-17-2022, 06:59 AM
if all variable from y is done than the variable z is running +2
What should it be? 1?
If so take out the z=z+1.
Otherwise, just a guess:
Sub testing()
Dim y As Long
Dim z As Long
For z = 1 To 42
For y = 3 To 8
Sheets("employees").Cells(y, 9).Copy Sheets("Time_data_01").Cells(2, 4).Offset(z, 0)
Next y
z = z + 1
Next z
End Sub

michael32
08-17-2022, 09:09 AM
The nr 1 it offset the cell. If I dont use z+1 then all of y is calculated in one cell. Z+1 is only for offsetting cell e.g. Cell a1 #z+1# a2 #z+1# a3..... Till z variable

p45cal
08-17-2022, 09:37 AM
I haven't the foggiest what you're trying to do.
Why dont you attach a small workbook with:
A sheet called employees
A sheet called Time_data_01 as it is before you run the macro
A sheet called Time_data_01Expected manually filled in as you expect the Time_data sheet to be after the macro is run.
And make it obvious by using different values where values are coming from in the expected sheet.