Background
I am new to VBA (as you will probably soon surmise), so maybe this is not exactly the right forum for me. I am working on a little project at work using Excel 2000 and its budled version of VBA (I work for a huge government organization that prides itself on its electronic office infrastructure and still only supplies employees with Office Small Business Edition).
The Project
I have produced a workbook with 2 worksheets. Worksheets 1 allows the user to input rows of data into a multicolumn table. When a command button is clicked a macro runs a while loop, each iteration copies the contents of a row into lables on Worksheet 2 and then prints off Worksheets 2 to produce a form used in our filing. That is the theory anyway.
The Code (simplified to copy only one item per row of data)
Private Sub CommandButton1_Click()
Dim counter As Integer
counter = 1
While Len(Worksheets("sheet1" ).Cells(counter, 1)) > 0
Worksheets("sheet2" ).Label1.Caption = Worksheets("sheet1" ).Cells counter, 1)
Worksheets("sheet2" ).PrintOut copies:=1
counter = counter + 1
Wend
End Sub
The Problem
My macro actually produces "x" copies of Worksheet 2 filled in with the contents of the first row of data from Worksheet 1, where "x " is the number of rows of data.
So, if Worksheet1 contained three rows of data (A1 to A3) each holding a single name; ie: Albert, Bernard and Charles, the output would be three copies of Worksheet 2, each with the name Albert printed on it.
By setting up a MsgBox to monitor the contents of Label1 during the execution of the loop, I can see that the label is getting updated with each iteration. However, it seems that the information being sent to the printer is not getting updated.
The Solution?
If anyone can please supply me with the cause of this problem and some sort of solution (my copy of Excel does not have acess to the Database functions,etc) I would be very grateful .
I am new to VBA (as you will probably soon surmise), so maybe this is not exactly the right forum for me. I am working on a little project at work using Excel 2000 and its budled version of VBA (I work for a huge government organization that prides itself on its electronic office infrastructure and still only supplies employees with Office Small Business Edition).
The Project
I have produced a workbook with 2 worksheets. Worksheets 1 allows the user to input rows of data into a multicolumn table. When a command button is clicked a macro runs a while loop, each iteration copies the contents of a row into lables on Worksheet 2 and then prints off Worksheets 2 to produce a form used in our filing. That is the theory anyway.
The Code (simplified to copy only one item per row of data)
Private Sub CommandButton1_Click()
Dim counter As Integer
counter = 1
While Len(Worksheets("sheet1" ).Cells(counter, 1)) > 0
Worksheets("sheet2" ).Label1.Caption = Worksheets("sheet1" ).Cells counter, 1)
Worksheets("sheet2" ).PrintOut copies:=1
counter = counter + 1
Wend
End Sub
The Problem
My macro actually produces "x" copies of Worksheet 2 filled in with the contents of the first row of data from Worksheet 1, where "x " is the number of rows of data.
So, if Worksheet1 contained three rows of data (A1 to A3) each holding a single name; ie: Albert, Bernard and Charles, the output would be three copies of Worksheet 2, each with the name Albert printed on it.
By setting up a MsgBox to monitor the contents of Label1 during the execution of the loop, I can see that the label is getting updated with each iteration. However, it seems that the information being sent to the printer is not getting updated.
The Solution?
If anyone can please supply me with the cause of this problem and some sort of solution (my copy of Excel does not have acess to the Database functions,etc) I would be very grateful .