Set Print Area with Dynamic Start Point

S

StonyfieldRob

I want to test a row for a date, for the start cell, for the print area.
Using that cell as a start, select 11 more columns, and 44 rows to set the
print area.

Sub Test1 ()


Range("G17").Select

Do While ((ActiveCell) <> Range("B4"))
ActiveCell.Offset(0, 1).Select
If ((ActiveCell) = Range("D2")) Then
Exit Do
End If
Loop

'SET PRINT AREA

((First cell of print area would be the cell the loop stops on.
Then down 44 row and over 12 columns))

ActiveSheet.PageSetup.PrintArea = SOME CODE

ActiveWindow.SelectedSheets.PrintPreview

End Sub
 
T

Tim Williams

Untested, but something like this might work

'****************************************
Dim c as range, ok as boolean
set c = activesheet.Range("G17")

Do while c.value<>activesheet.range("B4").value
if c.value = activesheet.range("D2").value then
ActiveSheet.PageSetup.PrintArea = _
c.resize(44,11).address()
ok=true
exit do
end if
set c=c.offset(1,0)
loop

if ok then ActiveWindow.SelectedSheets.PrintPreview
'******************************************

Tim
 
D

Don Guillett

Try this

Sub setprintarea()
lc = Cells(17, Columns.Count).End(xlToLeft).Column
Set mf = Range(Cells(17, "g"), Cells(17, lc)) _
..find(What:=Range("d2"), After:=Range("g17"), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not mf Is Nothing Then
'MsgBox mf.Column
Cells(17, mf.Column).Resize(4, 12).PrintPreview 'printOUT
End If
End Sub
 

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

Similar Threads

Dynamic Print Area 5
Print with sevral different print area's 2
Set print area 0
Between Dates Criteria 4
Remove Identical words 0
VBA for Dependents shortcut menu 0
Copy filtered data to sheet 2 1
Set Print Area 4

Top