Thread: Printing ranges
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
ALEX ALEX is offline
external usenet poster
 
Posts: 493
Default Printing ranges

I tried what you said but had no luck. This is what I have. Any ideas what I
did wrong?

Private Sub CommandButton1_Click()
Option Explicit
Sub testme01()
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = ActiveWorkbook.Names(Worksheets("sheet1").Range("t 4").Value) _
.RefersToRange
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Not a valid range!"
Exit Sub
End If

myRng.PrintOut preview:=True

End Sub

"Dave Peterson" wrote:

You can create a macro that looks at that cell with the formula and then tries
to print the range that's named in that cell.

I used A1 of sheet1 to contain the name--change it to what you need:

Option Explicit
Sub testme01()
Dim myRng As Range

Set myRng = Nothing
On Error Resume Next
Set myRng = ActiveWorkbook.Names(Worksheets("sheet1").Range("a 1").Value) _
.RefersToRange
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "Not a valid range!"
Exit Sub
End If

myRng.PrintOut preview:=True

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Alex wrote:

I have four sheets of the same document on one worksheet. I have written a
basic formula that counts the sheets that have data in them and returns a
number 1 thru 4. I have also named four ranges 1 thru 4 to reflect sheets
1&2, / 1,2,& 3, /etc.

My problem now is, How can I print these only the ranges that this cell
calls for?

I can add a print button to my sheet but what would the macro look like to
accomplish this?


--

Dave Peterson