Here is the macro I'm working with.
I have others that are very similar in that they all retrieve a page (table) and paste it into its own sheet in the same workbook, after which a series of minor formatting operations are performed (columns deleted, rows deleted, and columns resized).
Sub RealTimeStats()
'
' RealTimeStats Macro
' Macro recorded 10/14/2010 by Scott
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.nhl.com/ice/teamstats.htm?fetchKey=20112ALLAAAAll&sort=team.displayAbbrev&viewName=realTimeStats" _
, Destination:=Range("A1"))
.Name = _
"teamstats.htm?fetchKey=20112ALLAAAAll&sort=team.displayAbbrev&viewName=realTimeStats_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
Columns("A:A").Select
Selection.Delete Shift:=xlToLeft
Rows("1:8").Select
Range("A8").Activate
Selection.Delete Shift:=xlUp
Columns("A:A").ColumnWidth = 13.29
Range("A1").Select
End Sub
My question applies mostly to the bottom part of this code..
How can i re-arrange all this stuff so that it is on one line?
That is, how can I make the formatting part of this macro more VBA efficient?
Someone told me a while back that it was possible to group different commands and operations onto one line, saving alot of space, thereby making the code more efficient.
As a heads up, i know next to nothing about VBA specifically, though i have taken some C++ a while back (many years now) so i'm not a total alien when it comes to programming.
For excel, all my macros are 'recorded', so they end up being quite long and large, due to my inability to trim them myself and make them more efficient.
Bookmarks