Hey all,
I'm trying to have a macro move down one cell and resume from the start if it finds nothing, but I'm running into problems....
Thanks!![]()
Please Login or Register to view this content.
Hey all,
I'm trying to have a macro move down one cell and resume from the start if it finds nothing, but I'm running into problems....
Thanks!![]()
Please Login or Register to view this content.
Hello giantfan87,
What is the problem you are having?
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
It's giving me a runtime error and highlighting the "If foundrange is nothing then" line.
Hello giantfan87,
Your code snippet does not show if you are assigning the variable FoundRange to the Cells.Find statement. This would cause the error. You code should like similar to this...
![]()
Please Login or Register to view this content.
It's still giving me an error, says I need to define an object.
Hello giantfan87,
You should post your workbook for review.
MSG1 = MsgBox("This program may take several moments to complete depending on the number of accounts. Is the first account number selected?", vbYesNo)
If MSG1 = vbYes Then
Do
Selection.Copy
Sheets("1").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim foundrange As Range
Set foundrange = Cells.Find(What:=Range("A1"), after:=ActiveCell).Activate
Cells.Find(What:=Range("A1"), after:=ActiveCell).Activate
If foundrange Is Nothing Then
Sheets("Data").Select
ActiveCell.Offset(1, 0).Select
Run (Macro)
Else
End If
Sheets("1").Select
Cells.Find(What:="Value", after:=ActiveCell).Activate
ActiveCell.Offset(0, 1).Select
Selection.Copy
Sheets("Data").Select
ActiveCell.Offset(0, 3).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(1, -20).Select
Loop Until IsEmpty(ActiveCell)
Else
End If
End Sub
![]()
Please Login or Register to view this content.
Hello giantfan87,
My fault. I missed the Activate at the end of the Find statement. The code should be like this...
![]()
Please Login or Register to view this content.
Ok thanks... getting closer. How do I write the code if I want it to resume at a specific line if it cannot find what is in cell A1?
Hello giantfan87,
Do you mean a line in the code or a cell on the worksheet?How do I write the code if I want it to resume at a specific line if it cannot find what is in cell A1?
Sorry, a line in the code.
Hello giantfan87,
There are 2 ways to do this. You can number each line in your code or use a line label. A line label is a lot easier in my opinion.
The label must start in column 1 of the code module. If you put code on the same line as the label, add a colon (to the end of the label.
Use the GoTo statement to jump to the label. For example, Goto ErrHandler transfers execution to the ErrHandler.
How do you label a line?
Figured out how to label a line. Problem still persists as follows: I want it to diplay a message saying "works" if something is found. If nothing is found I want it to offset 1 row and go to line "nada". The way it is written it seems to be ignoring the activecell.offset lines.
![]()
Please Login or Register to view this content.
Hello giantfan87,
The ActiveCell should be moving to the next row. Is that not happening?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks