Z
zman
Below is macro code I wrote, not the whole thing but a sample. Th
problem is the Sub length for my code is to long. Is there a way t
compress this code?
Public Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub PR1_Click()
'
' PR1_Click Macro
' Macro recorded 6/1/2004 by Lee
'
Dim destrange As range
Dim smallrng As range
Dim newsh As Worksheet
Dim Ash As Worksheet
Set Ash = ActiveSheet
Set newsh = Worksheets.Add
newsh.Name = "pr1"
Ash.Select
range("A379").Select
newsh.PageSetup.TopMargin = Application.InchesToPoints(0.5)
newsh.PageSetup.TopMargin = 60
newsh.PageSetup.HeaderMargin = Application.InchesToPoints(0.5)
newsh.PageSetup.LeftHeader = "Estimate Sheet..."
newsh.PageSetup.CenterHeader = "Pioneer Fire Protection, Inc."
newsh.PageSetup.RightHeader = "&D"
newsh.PageSetup.CenterFooter = "Page &P of &N"
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
For Each smallrng In Selection.Areas
On Error GoTo errorhandler
smallrng = Ash.Cells.range("A381")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("B383")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo zero
Exit Sub
zero:
If Ash.Cells.range("B56") = "" Then GoTo one
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A56") & (" - ") & Ash.Cells.range("B56")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo one
Exit Sub
one:
If Ash.Cells.range("B57") = "" Then GoTo two
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A57") & (" - ") & Ash.Cells.range("B57")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo two
Exit Sub
and so on for about 200 more of the same with following consecutiv
numbers and ends like this...
onehundredfour:
If Ash.Cells.range("B162") = "" Then GoTo PT
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A162") & (" - ") & Ash.Cells.range("B162")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo PT
Exit Sub
PT:
' If you want a empty row between each area use +2
Next smallrng
errorhandler:
range("A53").Select
'Application.Run "PR1_Click"
Application.Run "PR2_Click"
End Sub
I had to split it at onehundredfour because I got the error of sub to
long, so then I wanted to consolidate the next sub (pr2) to continue o
but I am not successful with that.
What all this does is take a column of data from the (cover page
worksheet and puts it on a worksheet called (pr1) to be printed i
rough draft form.
When I try to consolidate, I go from worksheet (pr2) and try to put i
on worksheet (pr1). Starting where (pr1) left off to continue th
column of data down.
Any help would be greatful.
Thank
problem is the Sub length for my code is to long. Is there a way t
compress this code?
Public Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub PR1_Click()
'
' PR1_Click Macro
' Macro recorded 6/1/2004 by Lee
'
Dim destrange As range
Dim smallrng As range
Dim newsh As Worksheet
Dim Ash As Worksheet
Set Ash = ActiveSheet
Set newsh = Worksheets.Add
newsh.Name = "pr1"
Ash.Select
range("A379").Select
newsh.PageSetup.TopMargin = Application.InchesToPoints(0.5)
newsh.PageSetup.TopMargin = 60
newsh.PageSetup.HeaderMargin = Application.InchesToPoints(0.5)
newsh.PageSetup.LeftHeader = "Estimate Sheet..."
newsh.PageSetup.CenterHeader = "Pioneer Fire Protection, Inc."
newsh.PageSetup.RightHeader = "&D"
newsh.PageSetup.CenterFooter = "Page &P of &N"
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
For Each smallrng In Selection.Areas
On Error GoTo errorhandler
smallrng = Ash.Cells.range("A381")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("B383")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo zero
Exit Sub
zero:
If Ash.Cells.range("B56") = "" Then GoTo one
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A56") & (" - ") & Ash.Cells.range("B56")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo one
Exit Sub
one:
If Ash.Cells.range("B57") = "" Then GoTo two
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A57") & (" - ") & Ash.Cells.range("B57")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo two
Exit Sub
and so on for about 200 more of the same with following consecutiv
numbers and ends like this...
onehundredfour:
If Ash.Cells.range("B162") = "" Then GoTo PT
Set destrange = newsh.Cells(LastRow(newsh) + 1, 1)
smallrng = Ash.Cells.range("A55") & (" ----> ")
Ash.Cells.range("A162") & (" - ") & Ash.Cells.range("B162")
smallrng.Copy
destrange.PasteSpecial xlPasteValues
GoTo PT
Exit Sub
PT:
' If you want a empty row between each area use +2
Next smallrng
errorhandler:
range("A53").Select
'Application.Run "PR1_Click"
Application.Run "PR2_Click"
End Sub
I had to split it at onehundredfour because I got the error of sub to
long, so then I wanted to consolidate the next sub (pr2) to continue o
but I am not successful with that.
What all this does is take a column of data from the (cover page
worksheet and puts it on a worksheet called (pr1) to be printed i
rough draft form.
When I try to consolidate, I go from worksheet (pr2) and try to put i
on worksheet (pr1). Starting where (pr1) left off to continue th
column of data down.
Any help would be greatful.
Thank