Consulting

Results 1 to 2 of 2

Thread: Loop Thru Cells

  1. #1

    Loop Thru Cells

    Alright buddy hopefully you or someone can explain to me how to fix the little problem I ran into.

    I have two sheets,
    SheetA has a list of employe Nr.
    Sheet B has a form that needs to be filled out AND printed with each employee numbers on it (then vlookup formulas fill out the rest)
    Now I can copy paste each employee ID manually, but there are 330+ employees, that is a bit too much.
    I would like to copy cell A2 in Sheet A, paste it into A2 Sheet B AND print the form, then go to A3 Sheet A copy it, paste it into A3 in Sheet B and so on... I would like to repeat this process 337 times.
    I created this macro, but I don't know how to make it always choose the next cell in Sheet A AND repeat itself 337 times. (or depending on how many employees we have at a certain time)
    Sub Copy_Cell()
    ' Copy_Cell Macro
    Sheets("Sheet A").Select
    Range("A2").Select
    Selection.Copy
    Sheets("Sheet B").Select
    Range("A2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
    IgnorePrintAreas:=False
    End Sub
    SheetA.jpgSheetB.jpg
    I really appreciate any help and hope someone can show me a way to do it.
    Thank You
    Nick.
    Last edited by Aussiebear; 12-31-2017 at 01:32 PM. Reason: Added tags to submitted code

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Because only people who are changing from 32 bit to 64 bit will look at the
    Change VBA code to fit 64-bit thread, I moved your question to a new thread.

    Option Explicit
    
    Sub VBAX_SamT_Looping_Thru_Range()
    'For Help See: http://www.vbaexpress.com/forum/showthread.php?61656
    Dim IDList As Range
    Dim Cel As Range
    
    Set IDList = Sheets("Sheet A").Range(Range("A2"), Cells(Rows.Count, "A").End(xlUp))
    
    For Each Cel In IDList
       With Sheets("Sheet B")
        .Range("A2") = Cel
        .Calculate
        .PrintOut
      End With
    Next Cel
    
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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