arrancollins1983
New Member
- Joined
- Aug 12, 2011
- Messages
- 3
Hi to all, this is my first time on here so please bear with me.
I have created the code below in Excel 2010 vba, the code itself works fine but due to it running through some 20,000 lines, I was wondering if anyone could help show me how I can speed this up?
I am sure, like most of you, I am self taugh with Excel VBA so any tips will be greatly recieved.
Code:
Sub Prop_List()
Dim Rng As Range, rCell As Range
Dim a As Long
Dim BL, SH, BE, RO, BU, FL, HO, MA, GA As String
a = Range("Data_Entry1").Value
b = Range("Data_Entry1").Value + 4
BL = "Block"
SC = "Scheme"
SH = "Shelter"
BE = "Bedsit"
RO = "Room"
BU = "Bungalow"
FL = "Flat"
HO = "House"
MA = "Maisonette"
GA = "Garage"
Application.ScreenUpdating = False
If a = 0 Then
MsgBox "No Data to Update", vbOKOnly
Exit Sub
Else
If Range("A1").Value = 1 Then
MsgBox "Property List Data already Updated", vbOKOnly
Exit Sub
Else
Application.StatusBar = True
Application.StatusBar = "Please wait... Data is being Updated"
Application.Cursor = xlWait
Rows("5:5").Select
Selection.Copy
Rows("5:5").Resize(a).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Value = 1
Range("Data_Entry1").Offset(3, -4).Activate
Set Rng = Range("C5:C" & b)
For Each rCell In Rng.Cells
If InStr(1, rCell.Value, SC, vbTextCompare) Then rCell.Offset(0, 4).Value = SC
If InStr(1, rCell.Value, BL, vbTextCompare) Then rCell.Offset(0, 4).Value = BL
If InStr(1, rCell.Value, BE, vbTextCompare) Then rCell.Offset(0, 4).Value = BE
If InStr(1, rCell.Value, RO, vbTextCompare) Then rCell.Offset(0, 4).Value = RO
If InStr(1, rCell.Value, BU, vbTextCompare) Then rCell.Offset(0, 4).Value = BU
If InStr(1, rCell.Value, FL, vbTextCompare) Then rCell.Offset(0, 4).Value = FL
If InStr(1, rCell.Value, HO, vbTextCompare) Then rCell.Offset(0, 4).Value = HO
If InStr(1, rCell.Value, MA, vbTextCompare) Then rCell.Offset(0, 4).Value = MA
If InStr(1, rCell.Value, SH, vbTextCompare) Then rCell.Offset(0, 4).Value = SH
If InStr(1, rCell.Value, GA, vbTextCompare) Then rCell.Offset(0, 4).Value = GA
Next rCell
Range("Data_Entry1").Offset(4, 0).Resize(a).Select
Selection.Replace What:="", Replacement:="Other", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Data_Entry1").Offset(3, -5).Select
Application.ScreenUpdating = True
Application.StatusBar = False
Application.Cursor = xlDefault
MsgBox "Data Update Complete"
End If
End If
End Sub
I have created the code below in Excel 2010 vba, the code itself works fine but due to it running through some 20,000 lines, I was wondering if anyone could help show me how I can speed this up?
I am sure, like most of you, I am self taugh with Excel VBA so any tips will be greatly recieved.
Code:
Sub Prop_List()
Dim Rng As Range, rCell As Range
Dim a As Long
Dim BL, SH, BE, RO, BU, FL, HO, MA, GA As String
a = Range("Data_Entry1").Value
b = Range("Data_Entry1").Value + 4
BL = "Block"
SC = "Scheme"
SH = "Shelter"
BE = "Bedsit"
RO = "Room"
BU = "Bungalow"
FL = "Flat"
HO = "House"
MA = "Maisonette"
GA = "Garage"
Application.ScreenUpdating = False
If a = 0 Then
MsgBox "No Data to Update", vbOKOnly
Exit Sub
Else
If Range("A1").Value = 1 Then
MsgBox "Property List Data already Updated", vbOKOnly
Exit Sub
Else
Application.StatusBar = True
Application.StatusBar = "Please wait... Data is being Updated"
Application.Cursor = xlWait
Rows("5:5").Select
Selection.Copy
Rows("5:5").Resize(a).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Value = 1
Range("Data_Entry1").Offset(3, -4).Activate
Set Rng = Range("C5:C" & b)
For Each rCell In Rng.Cells
If InStr(1, rCell.Value, SC, vbTextCompare) Then rCell.Offset(0, 4).Value = SC
If InStr(1, rCell.Value, BL, vbTextCompare) Then rCell.Offset(0, 4).Value = BL
If InStr(1, rCell.Value, BE, vbTextCompare) Then rCell.Offset(0, 4).Value = BE
If InStr(1, rCell.Value, RO, vbTextCompare) Then rCell.Offset(0, 4).Value = RO
If InStr(1, rCell.Value, BU, vbTextCompare) Then rCell.Offset(0, 4).Value = BU
If InStr(1, rCell.Value, FL, vbTextCompare) Then rCell.Offset(0, 4).Value = FL
If InStr(1, rCell.Value, HO, vbTextCompare) Then rCell.Offset(0, 4).Value = HO
If InStr(1, rCell.Value, MA, vbTextCompare) Then rCell.Offset(0, 4).Value = MA
If InStr(1, rCell.Value, SH, vbTextCompare) Then rCell.Offset(0, 4).Value = SH
If InStr(1, rCell.Value, GA, vbTextCompare) Then rCell.Offset(0, 4).Value = GA
Next rCell
Range("Data_Entry1").Offset(4, 0).Resize(a).Select
Selection.Replace What:="", Replacement:="Other", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Data_Entry1").Offset(3, -5).Select
Application.ScreenUpdating = True
Application.StatusBar = False
Application.Cursor = xlDefault
MsgBox "Data Update Complete"
End If
End If
End Sub