Marklarbear
Board Regular
- Joined
- Nov 6, 2003
- Messages
- 119
- Office Version
- 365
- Platform
- Windows
Hi Guys
I have some VBA code that I got assistnace with from the MrExcel fraternity previously.... what I want it to do now is to run the same steps on the next sheet in the book (I have changed the text to orange colour from where the next sheet kicks in).
I'm getting the following error when moving to the next sheet:
it identifies 'Dim a' as the issue - is the fix as easy as changing the Dim assignments? ie changing all the DIM references to different letters when the next sheet is selected? or is there another way?
VBA Code:
Sub AHT_Outliers_Adjustment()
' Friday AHT Sheet.
' Changes the first digit if greater than 999 or less than 100 to target AHT range
Dim a, b, i As Long, j As Long
a = Range("B4:K99")
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
' If number is greater than 4 digits - remove thousands digits and change hundred digit to 4
' (Reduces any AHT from greater than 1000 to a minimum of 400)
If Len(CStr(a(i, j))) >= 4 Then
b(i, j) = "4" & Right(a(i, j), 2)
' If number is greater than 1 digit but less than 3 digits - add a 2 to the front (increases a 2 digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 2 Then
b(i, j) = "2" & Right(a(i, j), 2)
' If number is less than 2 digits - add 20 to the front (increases a single digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 1 Then
b(i, j) = "20" & Right(a(i, j), 2)
Else
b(i, j) = a(i, j)
End If
Next j
Next i
Range("B4").Resize(UBound(b, 1), UBound(b, 2)).Value = b
' Calls and runs the StartWithFour macro
Call StartWithFour
' calls and runs the ClearCells macro
Call ClearCells
' Repeat outlier steps for Saturday AHT sheet.
Sheets("Saturday AHT").Select
' Changes the first digit if greater than 999 or less than 100 to target AHT range
Dim a, b, i As Long, j As Long
a = Range("B4:K99")
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
' If number is greater than 4 digits - remove thousands digits and change hundred digit to 4
' (Reduces any AHT from greater than 1000 to a minimum of 400)
If Len(CStr(a(i, j))) >= 4 Then
b(i, j) = "4" & Right(a(i, j), 2)
' If number is greater than 1 digit but less than 3 digits - add a 2 to the front (increases a 2 digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 2 Then
b(i, j) = "2" & Right(a(i, j), 2)
' If number is less than 2 digits - add 20 to the front (increases a single digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 1 Then
b(i, j) = "20" & Right(a(i, j), 2)
Else
b(i, j) = a(i, j)
End If
Next j
Next i
Range("B4").Resize(UBound(b, 1), UBound(b, 2)).Value = b
' Calls and runs the StartWithFour macro
Call StartWithFour
' calls and runs the ClearCells macro
Call ClearCells
End Sub
I have some VBA code that I got assistnace with from the MrExcel fraternity previously.... what I want it to do now is to run the same steps on the next sheet in the book (I have changed the text to orange colour from where the next sheet kicks in).
I'm getting the following error when moving to the next sheet:
it identifies 'Dim a' as the issue - is the fix as easy as changing the Dim assignments? ie changing all the DIM references to different letters when the next sheet is selected? or is there another way?
VBA Code:
Sub AHT_Outliers_Adjustment()
' Friday AHT Sheet.
' Changes the first digit if greater than 999 or less than 100 to target AHT range
Dim a, b, i As Long, j As Long
a = Range("B4:K99")
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
' If number is greater than 4 digits - remove thousands digits and change hundred digit to 4
' (Reduces any AHT from greater than 1000 to a minimum of 400)
If Len(CStr(a(i, j))) >= 4 Then
b(i, j) = "4" & Right(a(i, j), 2)
' If number is greater than 1 digit but less than 3 digits - add a 2 to the front (increases a 2 digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 2 Then
b(i, j) = "2" & Right(a(i, j), 2)
' If number is less than 2 digits - add 20 to the front (increases a single digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 1 Then
b(i, j) = "20" & Right(a(i, j), 2)
Else
b(i, j) = a(i, j)
End If
Next j
Next i
Range("B4").Resize(UBound(b, 1), UBound(b, 2)).Value = b
' Calls and runs the StartWithFour macro
Call StartWithFour
' calls and runs the ClearCells macro
Call ClearCells
' Repeat outlier steps for Saturday AHT sheet.
Sheets("Saturday AHT").Select
' Changes the first digit if greater than 999 or less than 100 to target AHT range
Dim a, b, i As Long, j As Long
a = Range("B4:K99")
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
' If number is greater than 4 digits - remove thousands digits and change hundred digit to 4
' (Reduces any AHT from greater than 1000 to a minimum of 400)
If Len(CStr(a(i, j))) >= 4 Then
b(i, j) = "4" & Right(a(i, j), 2)
' If number is greater than 1 digit but less than 3 digits - add a 2 to the front (increases a 2 digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 2 Then
b(i, j) = "2" & Right(a(i, j), 2)
' If number is less than 2 digits - add 20 to the front (increases a single digit AHT to a 3 digit AHT)
ElseIf Len(CStr(a(i, j))) = 1 Then
b(i, j) = "20" & Right(a(i, j), 2)
Else
b(i, j) = a(i, j)
End If
Next j
Next i
Range("B4").Resize(UBound(b, 1), UBound(b, 2)).Value = b
' Calls and runs the StartWithFour macro
Call StartWithFour
' calls and runs the ClearCells macro
Call ClearCells
End Sub