Consulting

Results 1 to 4 of 4

Thread: copy with loop double variable

  1. #1

    copy with loop double variable

    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
    Last edited by Aussiebear; 08-17-2022 at 05:45 PM. Reason: Added code tags to supplied code

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    Quote Originally Posted by michael32 View Post
    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
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    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

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,844
    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.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •