Help Understanding Excel Macro

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ericjohnson
    New Member
    • Aug 2008
    • 1

    #1

    Help Understanding Excel Macro

    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
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by ericjohnson
    ...
    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
    its a recorded macro, it doesn't do much more than someones' excel session where he/she set some autofilters, copy some things, paste other things and print some other things. And select, deselect and select again some views and cells.

    At least that seems to me. Oh and i wouldnt use Copy-Paste in a macro, that can lead you to disasters. Set some variants instead to save cells values, its faster and quite more reliable than the clipboard.

    Comment

    Working...