Vader
Registered User.
- Local time
- Today, 13:47
- Joined
- Jan 18, 2007
- Messages
- 16
Hello to everyone who reads or is a member of this Forum!
I was only reading and searching this forum, which I must say that is one of the best, if not "THE BEST" of it`s kind, until today - I have a problem with Excel VBA code! First of all, I`m not satisfied with the speed of my code, second, I have problems running it on computers which have older versions than MS Office 2003,third, I cannot insert Page/Print setup code that meets my needs.
About the speed - The reason I`m asking this question, is to learn about speeding up VBA code. So any suggestions are welcome.
Well here is my code, so take a look!
If you need the file which goes with the code, Please let me know!!!
Sub Vader_CreateMe()
ActiveSheet.Cells.Interior.ColorIndex = xlNone 'Remove color
ActiveSheet.Cells.MergeCells = False 'Unmerge cells
ActiveSheet.Rows(13).Clear 'Clear row A13, later to be heading row for columns
Range("C:C,D
,F:F,H:H,J:J,L:L,N:N,P
,R:R,T:T").Select 'Delete empty columns
Range("T1").Activate
Selection.Delete Shift:=xlToLeft
Rows("1:12").Select 'Delete previous header rows
Selection.Delete Shift:=xlUp
Range("A1").Select
'Insert column names in header row
ActiveCell.Resize(, 11) = Array("[ifra", "Komintent", "Do 15 dena", "Do 30 dena", "Do 60 dena", "Do 90 dena", "Do 180 dena", "Do 360 dena", "Nad 360 dena", "Dospeani pobaruvawa", "Nedospeani pobaruvawa")
'Delete empty rows
Columns("K:K").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'Delete values in column K (Nedospeani pobaruvanja),that equals 5 and under
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.DisplayPageBreaks = False
Dim lastrow As Long, r As Long
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "K").Value <= 5 Then
Rows(r).EntireRow.Delete
End If
Next r
ActiveSheet.DisplayPageBreaks = True
'Remove color
ActiveSheet.Cells.Interior.ColorIndex = xlNone
'Delete cells that seem empty
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Rng As Range, ix As Long
Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For ix = Rng.Count To 1 Step -1
If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
Rng.Item(ix).EntireRow.Delete
End If
Next
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'Arranges the header row
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
.Font.Name = "MAC C Swiss"
.Cells.RowHeight = 30
End With
'Remove all spaces from column A
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Selection.Range("A:A").Replace What:=Chr(160), _
Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=True
Selection.Range("A:A").Replace What:=Chr(32), _
Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'Apply header row color
Range("A1:K1").Interior.ColorIndex = 15
'Arranges columns A and B
Columns("A:B").EntireColumn.AutoFit
'Applies the number format
ActiveSheet.UsedRange.NumberFormat = "#,##0.00"
ActiveSheet.Range("A:A").NumberFormat = ""
ActiveSheet.Range("A:A").ColumnWidth = 9.5
ActiveSheet.Range("A:A").VerticalAlignment = xlCenter
ActiveSheet.Range("A:A").HorizontalAlignment = xlCenter
'Format row height and font size
ActiveSheet.UsedRange.RowHeight = 30
ActiveSheet.UsedRange.Font.Size = 12
ActiveSheet.UsedRange.VerticalAlignment = xlCenter
'Sorting of column K in descending way
Columns("A:K").Select
Selection.Sort Key1:=Range("K2"), Order1:=xlDescending
Columns("C:K").EntireColumn.AutoFit
'Insert borders within used range
ActiveSheet.UsedRange.Borders.LineStyle = xlContinuous
End Sub
I was only reading and searching this forum, which I must say that is one of the best, if not "THE BEST" of it`s kind, until today - I have a problem with Excel VBA code! First of all, I`m not satisfied with the speed of my code, second, I have problems running it on computers which have older versions than MS Office 2003,third, I cannot insert Page/Print setup code that meets my needs.
About the speed - The reason I`m asking this question, is to learn about speeding up VBA code. So any suggestions are welcome.
Well here is my code, so take a look!
If you need the file which goes with the code, Please let me know!!!
Sub Vader_CreateMe()
ActiveSheet.Cells.Interior.ColorIndex = xlNone 'Remove color
ActiveSheet.Cells.MergeCells = False 'Unmerge cells
ActiveSheet.Rows(13).Clear 'Clear row A13, later to be heading row for columns
Range("C:C,D


Range("T1").Activate
Selection.Delete Shift:=xlToLeft
Rows("1:12").Select 'Delete previous header rows
Selection.Delete Shift:=xlUp
Range("A1").Select
'Insert column names in header row
ActiveCell.Resize(, 11) = Array("[ifra", "Komintent", "Do 15 dena", "Do 30 dena", "Do 60 dena", "Do 90 dena", "Do 180 dena", "Do 360 dena", "Nad 360 dena", "Dospeani pobaruvawa", "Nedospeani pobaruvawa")
'Delete empty rows
Columns("K:K").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
'Delete values in column K (Nedospeani pobaruvanja),that equals 5 and under
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveSheet.DisplayPageBreaks = False
Dim lastrow As Long, r As Long
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
For r = lastrow To 1 Step -1
If Cells(r, "K").Value <= 5 Then
Rows(r).EntireRow.Delete
End If
Next r
ActiveSheet.DisplayPageBreaks = True
'Remove color
ActiveSheet.Cells.Interior.ColorIndex = xlNone
'Delete cells that seem empty
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Rng As Range, ix As Long
Set Rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For ix = Rng.Count To 1 Step -1
If Trim(Replace(Rng.Item(ix).Text, Chr(160), Chr(32))) = "" Then
Rng.Item(ix).EntireRow.Delete
End If
Next
done:
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'Arranges the header row
Rows("1:1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Font.Bold = True
.Font.Name = "MAC C Swiss"
.Cells.RowHeight = 30
End With
'Remove all spaces from column A
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Selection.Range("A:A").Replace What:=Chr(160), _
Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=True
Selection.Range("A:A").Replace What:=Chr(32), _
Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
'Apply header row color
Range("A1:K1").Interior.ColorIndex = 15
'Arranges columns A and B
Columns("A:B").EntireColumn.AutoFit
'Applies the number format
ActiveSheet.UsedRange.NumberFormat = "#,##0.00"
ActiveSheet.Range("A:A").NumberFormat = ""
ActiveSheet.Range("A:A").ColumnWidth = 9.5
ActiveSheet.Range("A:A").VerticalAlignment = xlCenter
ActiveSheet.Range("A:A").HorizontalAlignment = xlCenter
'Format row height and font size
ActiveSheet.UsedRange.RowHeight = 30
ActiveSheet.UsedRange.Font.Size = 12
ActiveSheet.UsedRange.VerticalAlignment = xlCenter
'Sorting of column K in descending way
Columns("A:K").Select
Selection.Sort Key1:=Range("K2"), Order1:=xlDescending
Columns("C:K").EntireColumn.AutoFit
'Insert borders within used range
ActiveSheet.UsedRange.Borders.LineStyle = xlContinuous
End Sub