CODE WORKS. BUT LOOP IS LOPPING MORE THAN ONE NORMAL TIME TO GET RESULTS AND MOVING TO NEXT BIT. iT LOOPING TOO MANY TIMES OVER AND OVER AGAIN, REPEATING ITSELF (GETS THE RIGHT RESUTS THOUGH, BUT REPEATED RESULLTS), BEFORE FINISHING A SECTION AND MOVING ON TO THE NEXT SHEET. CAN ANYONE HELP ,ME/FIX MY CODE?
SO ITS NOT AN INFINITE LOOP, ITS NOT STUCK, BUT PERHAPS NOT WELL WRITTEN.
This is a piece of code I put together last night pushing to do so, in a rush, to ''detect'' #REFS! my way. Im quite pleased with the simpleton but obvious to me way I am seeking any error or ref in the spreadsheets, with my code.
However, That's not what my question is about. My question is : why is my search looping over x2, x3, (and maybe more) time per worksheet.??
My question is not about the loop over the worksheets. I can live with that and that works quite fine (taking that bit from the internet and there are other ways too , and have used it before. so that but works fine). Its about the internal loop which does the actual checking over the used areas, the columns and rows. I did it in a rush and Im still shacking, as I stlll cant concentrate on it clearly properly because shannanigans I feel work & the vapidly young criminal areas i live in is making nurveous/nuts. (althiugh I could be paranoid, hungry exhausted idk. so Ignore the last phrase. ) This post might have to be deleted edied in future. Yes i know , to many I appear mad/craxey
I think I am glad at just about getting it to loop as if it was a normal
call, and a. atleast it worked b... moved/does loop. But it loops too many times before moving on to the next worksheet.
I think this is causing it :
, i.e. is that not right?? But that piece that is making it work (althiugh it does *x times, too many times, going back on itself an repeating. Thats what I need to fix and sort out.)
Whats the proper way to write what I've done and trying to do?? How should write that , or what should I declare-do to make it loop maturely/sanely (as it was doing when it was only a 1 dimensional single range)??
I have a hint hunch my whole code is much too innefcient for you guys here, and too basic, but since I am completely on my own in excel and an eager "newbie novice" at this doing it inbetween jobs and other thinhgs, Im happy that its working, that It works (even tho its is appearing to work ''badly"). I just need to address that way im looping-'caling the ranges/areas to search' (also found that - I THINK - it seems so by eye - that its looping down and accross rows at the Same Time!?)
Try it yourselves, and please help me out. What have I done wrong/how can i improve the looping at least, and maybe is there other things I neeed to drop/add change to the whole thing to work for more straughtforward/efficeitnly.??
Many thanks for your help and time in advance,
S.DW
any assistance?? help?? would be sincerely appreciated.
SO ITS NOT AN INFINITE LOOP, ITS NOT STUCK, BUT PERHAPS NOT WELL WRITTEN.
This is a piece of code I put together last night pushing to do so, in a rush, to ''detect'' #REFS! my way. Im quite pleased with the simpleton but obvious to me way I am seeking any error or ref in the spreadsheets, with my code.
However, That's not what my question is about. My question is : why is my search looping over x2, x3, (and maybe more) time per worksheet.??
My question is not about the loop over the worksheets. I can live with that and that works quite fine (taking that bit from the internet and there are other ways too , and have used it before. so that but works fine). Its about the internal loop which does the actual checking over the used areas, the columns and rows. I did it in a rush and Im still shacking, as I stlll cant concentrate on it clearly properly because shannanigans I feel work & the vapidly young criminal areas i live in is making nurveous/nuts. (althiugh I could be paranoid, hungry exhausted idk. so Ignore the last phrase. ) This post might have to be deleted edied in future. Yes i know , to many I appear mad/craxey
VBA Code:
Sub FindRefsandErrorsinWorkbookBySheets()
Dim lastColumn As Integer
Dim myCell As Range
Dim LastRow As Long
Dim ws As Worksheet
'Dim starting_ws As Worksheet
'Set starting_ws = ActiveSheet 'remember which worksheet is active in the beginning
For Each ws In ThisWorkbook.Worksheets
ws.Activate
lastColumn = ws.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
Dim usedRows As Long
usedRows = ws.UsedRange.Rows.Count
For cols = 1 To lastColumn
LastRow = Cells(usedRows, cols).End(xlUp).Row
For Each myCell In Range(cols & ":" & LastRow + 1) ' & ":" & LastRow + 1
If myCell.Text = "#REF!" Then
myCell.Offset(0, 1) = "This was a ref in " & myCell.Address
MsgBox "Ref Found in " & myCell.Address
Else:
If IsError(myCell.Value) Then
myCell.Offset(0, 1) = "Do you know you had different tyoe of error in " & myCell.Address & "???"
End If
End If
Next myCell
Next cols
MsgBox ActiveWorkbook.Worksheets(I).Name
Next ws
End Sub
I think I am glad at just about getting it to loop as if it was a normal
VBA Code:
Range("A1:A"&LastRow+1)
I think this is causing it :
VBA Code:
For Each myCell In Range(cols & ":" & LastRow + 1)
Whats the proper way to write what I've done and trying to do?? How should write that , or what should I declare-do to make it loop maturely/sanely (as it was doing when it was only a 1 dimensional single range)??
I have a hint hunch my whole code is much too innefcient for you guys here, and too basic, but since I am completely on my own in excel and an eager "newbie novice" at this doing it inbetween jobs and other thinhgs, Im happy that its working, that It works (even tho its is appearing to work ''badly"). I just need to address that way im looping-'caling the ranges/areas to search' (also found that - I THINK - it seems so by eye - that its looping down and accross rows at the Same Time!?)
Try it yourselves, and please help me out. What have I done wrong/how can i improve the looping at least, and maybe is there other things I neeed to drop/add change to the whole thing to work for more straughtforward/efficeitnly.??
Many thanks for your help and time in advance,
S.DW
any assistance?? help?? would be sincerely appreciated.
Last edited: