double-quotes single-quotes and variables

T

Terry

Assuming the following is valid code, how do i code for the variable
rngWeekNum?

Worksheets("Roster").PageSetup.PrintArea = "" & rngWeekNum & """"

any help would be most gratefully received.

TIA
Terry
 
F

Frank Kabel

Hi Terry
if rngWeekNum is a range object try
Worksheets("Roster").PageSetup.PrintArea rngWeekNum.address
 
T

Terry

It doesn't appear to be a range *object* as it didn't work (excuse my
ignorance!).
This worked though...

Worksheets("Roster").PageSetup.PrintArea = rngWeekNum

Here's the code (don't laugh, now!):

Dim rngWeekNum As String

' concat the string "Week_" with the number in the indicated cell
' returns Week_n, e.g. Week_1, Week_2
rngWeekNum = "Week_" & Worksheets("Roster").Cells(2, 17)

' sets the print area to Week_n - a predefined Range
Worksheets("Roster").PageSetup.PrintArea = rngWeekNum

' Preview the print or comment-out and
' uncomment the line that follows to print directly
ActiveWindow.SelectedSheets.PrintPreview

' print command extracted by recording a macro
'ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

I'm going to try to extract the Range name directly from a combobox using
the helpful replies i've received elsewhere in this forum. But for now,
that'll do nicely. Thanks for your help, Frank.

Terry
 

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