First off, I have used this module on many worksheets with no problems. But for some weird reason, it's going wacko on the current worksheet I was working on! For the life of me, I can see why it might have a problem, but yet how or why it got to that point is WELL beyond me! It may just be that I've overlooked something in my own code or design.
First, here is the code:
And here is the Debug.Print Output I got before I just broke into the execution, as it appeared it would never end:
And actually, that wasn't all of the debug.print info, because apparently, there is a limit to the Immediate window text, so it just overwrites itself after a while.
This is the VERY FIRST instance of the 1004 error (debug.print output):
A separate question I'd like to pose is this: is it possible to edit the VBA settings so that there is no limit or else a much higher limit than the default settings allow?
Any advice on how I got to the error, and how to correct this would be GREATLY appreciated.
--
"If to err is human, then I must be some kind of human!" -Me
First, here is the code:
Code:
Private Sub TrimCells()
'This Macro is used to "clean up" workbooks in that it removes leading and trailing spaces in cells.
'Doing this helps to make sure that formulas compare values between cells correctly when comparing is necessary.
'*****I need at some time to add in code for finding the last portion of text on the workbook, and therefore,
'*****force the area of review to be correct dynamically. That way, I do not have to edit the code each time
'*****in order for the row and column counts to be accurate.
Dim wb As Workbook
Dim ws As Worksheet
Dim x As Long 'Row
Dim y As Long 'Column
On Error GoTo ErrHandle
Set wb = ActiveWorkbook
Application.ScreenUpdating = False
For Each ws In wb.Worksheets
If InStr(ws.Name, "Summary") Then
ElseIf ws.Name = "SQL" Or ws.Name = "AccessVBA" Then
Else
ws.Activate
x = 1
y = 1
For y = 1 To 1500
For x = 1 To 150
ActiveSheet.Cells(x, y).Activate
If Len(ActiveCell.Formula) > 0 And Len(ActiveCell.Formula) < 5 Then
' If InStr(ActiveCell.Formula, "yes") Or InStr(ActiveCell.Formula, "Yes") Or InStr(ActiveCell.Formula, "yes") Or InStr(ActiveCell.Formula, "no") Then
ActiveCell.Formula = Trim(ActiveCell.Formula)
' End If
End If
Next x
Next y
End If
Next ws
Set ws = Nothing
Set wb = Nothing
Application.ScreenUpdating = True
Exit Sub
ErrHandle:
If Err.Number = 1004 Then
Debug.Print "1004 Error at Cell: " & ActiveCell.Address
Debug.Print " x = " & x & " y = " & y
Resume Next
Else
MsgBox "A Non-1004 Error has occurred in cell " & ActiveCell.Address & "!" & Chr(13) & Chr(13) & _
Err.Number & " " & Err.Description & " " & Chr(13) & _
"__________________________" & Chr(13) & _
Err.HelpContext, vbCritical, "Non-1004 (Not Common) Error Has Occurred"
Set ws = Nothing
Set wb = Nothing
Application.ScreenUpdating = True
End If
End Sub
And here is the Debug.Print Output I got before I just broke into the execution, as it appeared it would never end:
Code:
1004 Error at Cell: $IV$150
x = 70 y = 1443
1004 Error at Cell: $IV$150
x = 71 y = 1443
1004 Error at Cell: $IV$150
x = 72 y = 1443
1004 Error at Cell: $IV$150
x = 73 y = 1443
1004 Error at Cell: $IV$150
x = 74 y = 1443
1004 Error at Cell: $IV$150
x = 75 y = 1443
1004 Error at Cell: $IV$150
x = 76 y = 1443
1004 Error at Cell: $IV$150
x = 77 y = 1443
1004 Error at Cell: $IV$150
x = 78 y = 1443
1004 Error at Cell: $IV$150
x = 79 y = 1443
1004 Error at Cell: $IV$150
x = 80 y = 1443
1004 Error at Cell: $IV$150
x = 81 y = 1443
1004 Error at Cell: $IV$150
x = 82 y = 1443
1004 Error at Cell: $IV$150
x = 83 y = 1443
1004 Error at Cell: $IV$150
x = 84 y = 1443
1004 Error at Cell: $IV$150
x = 85 y = 1443
1004 Error at Cell: $IV$150
x = 86 y = 1443
1004 Error at Cell: $IV$150
x = 87 y = 1443
1004 Error at Cell: $IV$150
x = 88 y = 1443
1004 Error at Cell: $IV$150
x = 89 y = 1443
1004 Error at Cell: $IV$150
x = 90 y = 1443
1004 Error at Cell: $IV$150
x = 91 y = 1443
1004 Error at Cell: $IV$150
x = 92 y = 1443
1004 Error at Cell: $IV$150
x = 93 y = 1443
1004 Error at Cell: $IV$150
x = 94 y = 1443
1004 Error at Cell: $IV$150
x = 95 y = 1443
1004 Error at Cell: $IV$150
x = 96 y = 1443
1004 Error at Cell: $IV$150
x = 97 y = 1443
1004 Error at Cell: $IV$150
x = 98 y = 1443
1004 Error at Cell: $IV$150
x = 99 y = 1443
1004 Error at Cell: $IV$150
x = 100 y = 1443
1004 Error at Cell: $IV$150
x = 101 y = 1443
1004 Error at Cell: $IV$150
x = 102 y = 1443
1004 Error at Cell: $IV$150
x = 103 y = 1443
1004 Error at Cell: $IV$150
x = 104 y = 1443
1004 Error at Cell: $IV$150
x = 105 y = 1443
1004 Error at Cell: $IV$150
x = 106 y = 1443
1004 Error at Cell: $IV$150
x = 107 y = 1443
1004 Error at Cell: $IV$150
x = 108 y = 1443
1004 Error at Cell: $IV$150
x = 109 y = 1443
1004 Error at Cell: $IV$150
x = 110 y = 1443
1004 Error at Cell: $IV$150
x = 111 y = 1443
1004 Error at Cell: $IV$150
x = 112 y = 1443
1004 Error at Cell: $IV$150
x = 113 y = 1443
1004 Error at Cell: $IV$150
x = 114 y = 1443
1004 Error at Cell: $IV$150
x = 115 y = 1443
1004 Error at Cell: $IV$150
x = 116 y = 1443
1004 Error at Cell: $IV$150
x = 117 y = 1443
1004 Error at Cell: $IV$150
x = 118 y = 1443
1004 Error at Cell: $IV$150
x = 119 y = 1443
1004 Error at Cell: $IV$150
x = 120 y = 1443
1004 Error at Cell: $IV$150
x = 121 y = 1443
1004 Error at Cell: $IV$150
x = 122 y = 1443
1004 Error at Cell: $IV$150
x = 123 y = 1443
1004 Error at Cell: $IV$150
x = 124 y = 1443
1004 Error at Cell: $IV$150
x = 125 y = 1443
1004 Error at Cell: $IV$150
x = 126 y = 1443
1004 Error at Cell: $IV$150
x = 127 y = 1443
1004 Error at Cell: $IV$150
x = 128 y = 1443
1004 Error at Cell: $IV$150
x = 129 y = 1443
1004 Error at Cell: $IV$150
x = 130 y = 1443
1004 Error at Cell: $IV$150
x = 131 y = 1443
1004 Error at Cell: $IV$150
x = 132 y = 1443
1004 Error at Cell: $IV$150
x = 133 y = 1443
1004 Error at Cell: $IV$150
x = 134 y = 1443
1004 Error at Cell: $IV$150
x = 135 y = 1443
1004 Error at Cell: $IV$150
x = 136 y = 1443
1004 Error at Cell: $IV$150
x = 137 y = 1443
1004 Error at Cell: $IV$150
x = 138 y = 1443
1004 Error at Cell: $IV$150
x = 139 y = 1443
1004 Error at Cell: $IV$150
x = 140 y = 1443
1004 Error at Cell: $IV$150
x = 141 y = 1443
1004 Error at Cell: $IV$150
x = 142 y = 1443
1004 Error at Cell: $IV$150
x = 143 y = 1443
1004 Error at Cell: $IV$150
x = 144 y = 1443
1004 Error at Cell: $IV$150
x = 145 y = 1443
1004 Error at Cell: $IV$150
x = 146 y = 1443
1004 Error at Cell: $IV$150
x = 147 y = 1443
1004 Error at Cell: $IV$150
x = 148 y = 1443
1004 Error at Cell: $IV$150
x = 149 y = 1443
1004 Error at Cell: $IV$150
x = 150 y = 1443
1004 Error at Cell: $IV$150
x = 1 y = 1444
1004 Error at Cell: $IV$150
x = 2 y = 1444
1004 Error at Cell: $IV$150
x = 3 y = 1444
1004 Error at Cell: $IV$150
x = 4 y = 1444
1004 Error at Cell: $IV$150
x = 5 y = 1444
1004 Error at Cell: $IV$150
x = 6 y = 1444
1004 Error at Cell: $IV$150
x = 7 y = 1444
1004 Error at Cell: $IV$150
x = 8 y = 1444
1004 Error at Cell: $IV$150
x = 9 y = 1444
1004 Error at Cell: $IV$150
x = 10 y = 1444
1004 Error at Cell: $IV$150
x = 11 y = 1444
1004 Error at Cell: $IV$150
x = 12 y = 1444
1004 Error at Cell: $IV$150
x = 13 y = 1444
1004 Error at Cell: $IV$150
x = 14 y = 1444
1004 Error at Cell: $IV$150
x = 15 y = 1444
1004 Error at Cell: $IV$150
x = 16 y = 1444
1004 Error at Cell: $IV$150
x = 17 y = 1444
1004 Error at Cell: $IV$150
x = 18 y = 1444
And actually, that wasn't all of the debug.print info, because apparently, there is a limit to the Immediate window text, so it just overwrites itself after a while.
This is the VERY FIRST instance of the 1004 error (debug.print output):
Code:
1004 Error at Cell: $IV$150
x = 1 y = 257
A separate question I'd like to pose is this: is it possible to edit the VBA settings so that there is no limit or else a much higher limit than the default settings allow?
Any advice on how I got to the error, and how to correct this would be GREATLY appreciated.
--
"If to err is human, then I must be some kind of human!" -Me