Hello everyone,
I hope all of you have been doing great!
I've been (slowly) learning VBA recently and realized that it'd be good practice to include error handling in my code. The set up:
I'm linking a "profile" workbook to approx 60 other workbooks. As you can see from the below code, the same row (in every worksheet) in the profile will be dedicated to a specific external workbook. I have included a portion of the code, however, this is only one of the 60-ish loops that I have in the full code. The exact same loop is repeated 60-ish times, with only the row number and external references changed.
Is there a way to code VB to move to the next loop generally? I don't believe a OnError GoTo would be appropriate because depending on which of the 60+ loops in this code has an error, I'd like it to move to the next loop.
I hope that this is as clear as possible! If there's any suggestions to improving my coding, better practices or words of advice from a more knowledgeable individual, I would be in great appreciation
Kind Regards,
Anthony
I hope all of you have been doing great!
I've been (slowly) learning VBA recently and realized that it'd be good practice to include error handling in my code. The set up:
I'm linking a "profile" workbook to approx 60 other workbooks. As you can see from the below code, the same row (in every worksheet) in the profile will be dedicated to a specific external workbook. I have included a portion of the code, however, this is only one of the 60-ish loops that I have in the full code. The exact same loop is repeated 60-ish times, with only the row number and external references changed.
Is there a way to code VB to move to the next loop generally? I don't believe a OnError GoTo would be appropriate because depending on which of the 60+ loops in this code has an error, I'd like it to move to the next loop.
Code:
Sub ProfileUpdater_Demographics()
Dim i As Integer
Dim strLow As String
Dim strSim As String
Dim strHigh As String
strLow = "LOWER"
strSim = "similar"
strHigh = "HIGHER"
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
For i = 0 To Worksheets.Count - 2
Worksheets(ActiveSheet.Index + 1).Select
Range("A9").FormulaR1C1 = "=[50HNIndicators.xlsx]2013Indicators!R4C7"
Range("B9").FormulaR1C1 = "=[50HNSummaryPopGrowth2011.xlsx]Summary!R" & 6 + i & "C2"
Range("C9").FormulaR1C1 = "=[50HNSummaryPopGrowth2011.xlsx]Summary!R64C2"
If i = 0 Then
Range("D9").FormulaR1C1 = "=[50HNSummaryPopGrowth2011.xlsx]Notes_Table!R2C4"
Else
Range("D9").FormulaR1C1 = "=[50HNSummaryPopGrowth2011.xlsx]SigDiff!R" & 2 + i & "C2"
End If
If Range("D9") = "LOWER" Then
Range("D9").Font.ColorIndex = 5
ElseIf Range("D9") = "similar" Then
Range("D9").Font.Color = vbBlack
ElseIf Range("D9") = "HIGHER" Then
Range("D9").Font.ColorIndex = 5
End If
Next i
Worksheets(ActiveSheet.Index - 8).Select
I hope that this is as clear as possible! If there's any suggestions to improving my coding, better practices or words of advice from a more knowledgeable individual, I would be in great appreciation

Kind Regards,
Anthony