setting print ranges to print based on option

  • Thread starter bluegrassstateworker
  • Start date
B

bluegrassstateworker

Hi all,
I have a function that has radio boxes as a parameter selection. At
each radio box I have a macro assigned which looks similar to below
where I assign an upper row and a lower row for a range that I wish
to
print. The variable was defined as Global and as a String.

Sub RadioButtonSelection_1Example()
vrow1 = 98 'both vrow1 and vrow2 defined as global and long
vrow2 = 109
End Sub


Sub printme()
vrow1 = "A" & vrow1 'the final product will be A98 in this case
vrow2 = "A" & vrow2 'the final product will be A109 in this case
If e_agency = True Then
Range("A86:A97", "&vrow1:&vrow2").Select
Selection.PrintOut Copies:=1, Collate:=True
Else
Range("&vrow1:&vrow2").Select
Selection.PrintOut Copies:=1, Collate:=True
End If
End Sub
 
B

bluegrassstateworker

Hi all,
I have a function that has radio boxes as a parameter selection. At
each radio box I have a macro assigned which looks similar to below
where I assign an upper row and a lower row for a range that I wish
to
print. The variable was defined as Global and as a String.

Sub RadioButtonSelection_1Example()
vrow1 = 98 'both vrow1 and vrow2 defined as global and long
vrow2 = 109
End Sub

Sub printme()
vrow1 = "A" & vrow1 'the final product will be A98 in this case
vrow2 = "A" & vrow2 'the final product will be A109 in this case
If e_agency = True Then
Range("A86:A97", "&vrow1:&vrow2").Select
Selection.PrintOut Copies:=1, Collate:=True
Else
Range("&vrow1:&vrow2").Select
Selection.PrintOut Copies:=1, Collate:=True
End If
End Sub

I forgot to add that the ranges are on different worksheet (if that
makes any difference)
 
C

Carl Hartness

Did you state your problem?

I forgot to add that the ranges are on different worksheet (if that
makes any difference)- Hide quoted text -

- Show quoted text -
 
B

bluegrassstateworker

Did you state your problem?





- Show quoted text -

I am using Excel in this case as an electronic form. My problem is
that the above syntax is not working and I am unsure of the best way
to pass a radio box selection as a print range parameter; something in
the syntax (or logic) is wrong. Here is what I would like to do: If a
radio box is checked (A checkbox would work too) then I want to have a
range printed out. If there are multiple groups checked then I want
to include them in a single printout. In this case, I have a
worksheet containing the radio buttons and the user navigates
throughout various worksheets within the workbook. When finished, a
macro runs the printing of each section and a set of instructions
based on the selections made when the workbook was opened. I havent
seen any VBA examples to draw from for guidance.
 
C

cbhartness

Debug.Print Range("&vrow1:&vrow2").Address gives an error.
Without prepending "A" to vrows, use
Debug.Print Range(Cells(vrow1, 1), Cells(vrow2, 1)).Address

The multiple range is trickier. The key is to use a string to create
the compound address:
Debug.Print Range("A86:A97", "&vrow1:&vrow2").Address gives an error.
s$ = "A86:A97," & Range(Cells(vrow1, 1), Cells(vrow2, 1)).Address
Debug.Print Range(s$).Address

Hope this helps
Carl.
 

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


Top