By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 739 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

Help Understanding Excel Macro

P: 1
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(shtnam).Select
Application.Goto Reference:="R3C1"
If ActiveSheet.AutoFilterMode = False Then Range("a3").AutoFilter
Range("a3").AutoFilter field:=2, criteria1:="<>0", operator:=xlAnd, criteria2:="<>"

'copy sorted range from "shtnam" to printoutsheet

Worksheets(shtnam).Range("a1").Copy (Worksheets("print1").Range("a" & LineCount))
LineCount = LineCount + 1


Selection.CurrentRegion.Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Print1").Select
rn = "A" & LineCount
Range(rn).Select
ActiveSheet.Paste
ActiveCell.Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
Selection.EntireRow.Delete
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
LineCount = (Selection.Row) + 2

Worksheets(shtnam).Select
Range("a3").AutoFilter

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.PageSetup
.PrintArea = "$A$1:$P$46"
.CenterHeader = ""
.CenterFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.FitToPagesWide = 1
End With
Selection.PrintOut 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
Aug 6 '08 #1
Share this Question
Share on Google+
1 Reply


kadghar
Expert 100+
P: 1,295
...
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.
Aug 7 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.