Hi all,
Sorry to bother people with this, but I cannot seem to find what keeps crashing Excel in the following code. I already know the code is horrendous to look at as i'm not amazing at this, so if anyone could provide tips on keeping it efficient that would be awesome too.
Just to add, im not sure how but it keeps writing "Region" in a sheet that doesnt havnt the word "data" in, although my if statement says only sheets with the word data in?
Thanks.
Sorry to bother people with this, but I cannot seem to find what keeps crashing Excel in the following code. I already know the code is horrendous to look at as i'm not amazing at this, so if anyone could provide tips on keeping it efficient that would be awesome too.
Code:
Private Sub updateSheets()
Dim ws As Worksheet
Dim iRegion As Integer
Dim rRegionRange As Range
Dim iCurRow As Integer
Dim sBranch As String
Dim sBranchCol As String
iRegion = 0
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If Right(Trim(ws.Name), 4) = "data" Then
Cells(1, 1).Select
Do Until ActiveCell.Value = ""
If InStr("Region", ActiveCell.Value) Then
iRegion = 1
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Value = ""
iCurRow = ActiveCell.Row
sBranch = sBranchCol & iCurRow
ActiveCell.Value = Application.WorksheetFunction.Index(Sheets("MATCH").Range("C:C"), Application.WorksheetFunction.Match(sBranch, Sheets("MATCH").Range("A:A"), 0), 1)
ActiveCell.Offset(1, 0).Select
Loop
End If
If InStr("Property_Branch", ActiveCell.Value) Then
sBranchCol = ActiveCell.Column
End If
If InStr("Management_Service", ActiveCell.Value) Then
Do Until ActiveCell.Value = ""
If Not InStr("CRL - Letting & Full Management", ActiveCell.Value) Or InStr("L&P - Full Management", ActiveCell.Value) Or InStr("L&P - Full Management (Upfront)", ActiveCell.Value) Or InStr("CRL - Managed Upfront", ActiveCell.Value) Then
ActiveCell.EntireRow.Delete Shift:=xlUp
ActiveCell.Offset(1, 0).Select
End If
Loop
End If
ActiveCell.Offset(0, 1).Select
Loop
If iRegion = 0 Then
Cells(1, 1).Select
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = "Region"
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.Value = ""
iCurRow = ActiveCell.Row
sBranch = sBranchCol & iCurRow
ActiveCell.Value = Application.WorksheetFunction.Index(Sheets("MATCH").Range("C:C"), Application.WorksheetFunction.Match(sBranch, Sheets("MATCH").Range("A:A"), 0), 1)
ActiveCell.Offset(1, 0).Select
Loop
End If
End If
Next
Application.ScreenUpdating = True
End Sub
Just to add, im not sure how but it keeps writing "Region" in a sheet that doesnt havnt the word "data" in, although my if statement says only sheets with the word data in?
Thanks.