if then else

J

JeffH

Ok I'm not a VB programer.

However what I'm trying to do is copy a variable starting in cell A4 to D3
and then print (preview in this example) a report. Next the macro moves to
A5, copies the value in D3 and previews a report. Next the macro moves to
A6, copies the value in D3 and previews the report. Ok, I'm sure I'm
insulting you right now.

I have add "If Applicaition.ActiveCell = False Then Exit Sub" to stop
previewing the report when there is no longer a value in A6, A7, etc.

This approach is not very efficient because I don't know how to loop the
macro to to move down a cell, I'm actually typing the cell references in the
macro "R4C1", R5C1, etc. I'm sure this humoring you, but this is my 1st
attempt at this.

See below:

Application.Goto Reference:="R4C1"
If Application.ActiveCell = False Then Exit Sub
Application.CutCopyMode = False
Selection.Copy
Range("D3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintPreview
Application.Goto Reference:="R5C1"
If Application.ActiveCell = False Then Exit Sub
Selection.Copy
Range("D3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintPreview
Application.Goto Reference:="R6C1"
If Application.ActiveCell = False Then Exit Sub
Selection.Copy
Range("D3").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.PrintPreview
Application.Goto Reference:="R7C1"
If Application.ActiveCell = False Then Exit Sub
 
F

FSt1

hi
if i understand you, this might be what your want....
Sub movedown()
Dim d As Range
Dim lr As Long
Set d = Range("D3")
'change the print area to suit your data
ActiveSheet.PageSetup.PrintArea = "$A$1:$E$14"
'find the last row in column A
lr = Cells(Rows.Count, "A").End(xlUp).Row
For Each cell In Range("A4:A" & lr)
d = cell.Value
'change the sheet name to suit
Worksheets("Sheet1").PrintPreview
Next cell
End Sub

Regards
FSt1
 
R

Rick Rothstein \(MVP - VB\)

For Each cell In Range("A4:A" & lr)
d = cell.Value
'change the sheet name to suit
Worksheets("Sheet1").PrintPreview
Next cell

Or, alternately, for the loop above, this looping method...

For x = 4 To lr
d.Value = Cells(x, "A").Value
'change the sheet name to suit
Worksheets("Sheet1").PrintPreview
Next

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top