I've got a macro that has already been written for an Excel spreadsheet used for estimating at work. I know enough VB to write very basic macros, but I cannot understand the logic and purpose behind this function. It is called in several of the other macros already written for the worksheet. Here is the macro:
Function ExSht(shtnam As String)
Dim rn As String
Dim a As String
Worksheets(shtn am).Select
Application.Got o Reference:="R3C 1"
If ActiveSheet.Aut oFilterMode = False Then Range("a3").Aut oFilter
Range("a3").Aut oFilter field:=2, criteria1:="<>0 ", operator:=xlAnd , criteria2:="<>"
'copy sorted range from "shtnam" to printoutsheet
Worksheets(shtn am).Range("a1") .Copy (Worksheets("pr int1").Range("a " & LineCount))
LineCount = LineCount + 1
Selection.Curre ntRegion.Select
Selection.Copy
ActiveWindow.Sc rollWorkbookTab s Position:=xlLas t
Sheets("Print1" ).Select
rn = "A" & LineCount
Range(rn).Selec t
ActiveSheet.Pas te
ActiveCell.Sele ct
Application.Cut CopyMode = False
Selection.Entir eRow.Delete
Selection.Entir eRow.Delete
Selection.End(x lDown).Select
Selection.End(x lDown).Select
Selection.End(x lUp).Select
LineCount = (Selection.Row) + 2
Worksheets(shtn am).Select
Range("a3").Aut oFilter
End Function
Sub printIt100()
Dim shtnam(3) As String
shtnam(0) = "Item100#1"
shtnam(1) = "Item100#2"
shtnam(2) = "Item100#3"
shtnam(3) = "Item100#4"
Dim nam As Variant
For Each nam In shtnam
Worksheets(nam) .Select
Range("a1:p46") .Select
If Range("j21") > 0 Then
With ActiveSheet.Pag eSetup
.PrintArea = "$A$1:$P$46 "
.CenterHeader = ""
.CenterFooter = ""
.LeftMargin = Application.Inc hesToPoints(0.5 )
.RightMargin = Application.Inc hesToPoints(0.5 )
.FitToPagesWide = 1
End With
Selection.Print Out Copies:=1
End If
Next
End Sub
If someone would be able to walk me through this functions steps, that would be perfect. This macro works, I just don't understand it's methods. So all I need is a thorough explanation.
Thanks,
Eric
Function ExSht(shtnam As String)
Dim rn As String
Dim a As String
Worksheets(shtn am).Select
Application.Got o Reference:="R3C 1"
If ActiveSheet.Aut oFilterMode = False Then Range("a3").Aut oFilter
Range("a3").Aut oFilter field:=2, criteria1:="<>0 ", operator:=xlAnd , criteria2:="<>"
'copy sorted range from "shtnam" to printoutsheet
Worksheets(shtn am).Range("a1") .Copy (Worksheets("pr int1").Range("a " & LineCount))
LineCount = LineCount + 1
Selection.Curre ntRegion.Select
Selection.Copy
ActiveWindow.Sc rollWorkbookTab s Position:=xlLas t
Sheets("Print1" ).Select
rn = "A" & LineCount
Range(rn).Selec t
ActiveSheet.Pas te
ActiveCell.Sele ct
Application.Cut CopyMode = False
Selection.Entir eRow.Delete
Selection.Entir eRow.Delete
Selection.End(x lDown).Select
Selection.End(x lDown).Select
Selection.End(x lUp).Select
LineCount = (Selection.Row) + 2
Worksheets(shtn am).Select
Range("a3").Aut oFilter
End Function
Sub printIt100()
Dim shtnam(3) As String
shtnam(0) = "Item100#1"
shtnam(1) = "Item100#2"
shtnam(2) = "Item100#3"
shtnam(3) = "Item100#4"
Dim nam As Variant
For Each nam In shtnam
Worksheets(nam) .Select
Range("a1:p46") .Select
If Range("j21") > 0 Then
With ActiveSheet.Pag eSetup
.PrintArea = "$A$1:$P$46 "
.CenterHeader = ""
.CenterFooter = ""
.LeftMargin = Application.Inc hesToPoints(0.5 )
.RightMargin = Application.Inc hesToPoints(0.5 )
.FitToPagesWide = 1
End With
Selection.Print Out Copies:=1
End If
Next
End Sub
If someone would be able to walk me through this functions steps, that would be perfect. This macro works, I just don't understand it's methods. So all I need is a thorough explanation.
Thanks,
Eric
Comment