Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro/VB Error Message

Status
Not open for further replies.

mtdew

Technical User
Dec 9, 2007
77
US
I had a macro I developed in Excel that I was trying to incorporate into visual basic to print a specific range from each sheet except for sheets with specific names. But it doesn't seem to move off of the first sheet, named Menu, and it wants to print what is on the menu sheet. Thus far I have:

Private Sub CommandButton3_Click()

Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
For Each sh In ThisWorkbook.Worksheets
If sh.Name <> "Template" And sh.Name <> "names" And sh.Name <> "Menu" And sh.Name <> "Reports" And sh.Name <> "Master" Then

Range("X1:AG43").Select
Selection.PrintOut Copies:=1

End If
Next
On Error Resume Next
End Sub

Any suggestions?
 
You need to re-post in the VBA (=macro) forum - forum707

When posting programming code use TGML: precede the code with the
Code:
tag and end it with [ /code] tag. This will aid in formatting your programming code correctly.

Before your IF add the line:
MsgBox (sh.Name) or add a watch on sh.name

Then step through your code to see what is happening.
Are the sheets in the workbook containing the code (ThisWorkbook)?



Gavin
 
I did as you suggested: reposted tried the MsgBox. The MsgBox showed me it was going through each of the sheets. Apparently what I'm doing wrong is going through each of the sheets but only printing the range from the first sheet. Do you know how to express it?
Something like:

sh.name.Range("X1:AG43").Select?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top