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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with copying worksheet in Excel VBA

Status
Not open for further replies.

Goska

Programmer
Jun 21, 2001
74
US
I have a problem that is going to drive me nuts. I am doing something just slightly wrong. I am trying to copy a worksheet so I can print it without a gray background to save toner, and for some reason I keep getting errors when I do this copy. Everything else works fine but the copy.

I have a button which does:
Private Sub CommandButton3_Click()
Dim Num As Integer
Dim i As Integer
Dim SecName As String

Call Printing.GetMaxRange(Num)

If (Num <> 1) Then
For i = 1 To Num
SecName = &quot;SECTION_&quot; & i
Call Printing.PrintMe(SecName)
Next i
Else
SecName = &quot;SECTION_1&quot;
Call Printing.PrintMe(SecName)
End If
end sub


Which calls the Sub()

Sub PrintMe(OldName As String)
Dim Valid As Boolean
Dim NewName As String

Sheets(OldName).Select
Sheets(OldName).Copy BEFORE:=Sheets(&quot;COVER_SHEET&quot;)
end sub

And the copy statement above is giving me lots of trouble. Sometimes it works, and sometimes it doesn't. Usually doesn't. The sheets I am working on are Section_1, Section_2, and so on through Section_i, where i is a maximum defined by how many sheets I created. And I used this same method to create all of these sheets that are now giving me problems.

All of the Section_i sheets are unhidden, and there is no protection on the workbook.
 
Solved my own problem, for this case at least. I've been cussing at the computer for 3 days on this one, and I just gave up and cheated. I made a new sheet named BLANK, and I'm just copying all of the info in my print range over to that one, reformatting it, and printign from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top