PDA

View Full Version : Loop Thru Cells



Ifortesi Daj
12-30-2017, 11:30 AM
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

2125721258
I really appreciate any help and hope someone can show me a way to do it.
Thank You
Nick.

SamT
12-31-2017, 12:40 PM
Because only people who are changing from 32 bit to 64 bit will look at the
Change VBA code to fit 64-bit (http://www.vbaexpress.com/forum/showthread.php?61231-Change-VBA-code-to-fit-64-bit-environment)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