The macro is suppose to:
1. search an entire sheet called "babies" for a given phrase ("puppies")
2. copy each row with the phrase ("puppies")
3. paste each row into the "dogs" sheet
The for loop should use the countif function to tell it how many times to loop and each loop when copy/paste.
I get the "code execution has been interrupted" error and the yellow error points to the "Next lloop" line.
Any thoughts???
[code]
Sub complete()
Dim lloop As Long
Dim rFound As Range
Set rFound = Range("A2")
For lloop = 1 To WorksheetFunction.CountIf(Sheets("babies").Range("B:B"), "puppies")
Set rFound = ActiveSheet.UsedRange.Find _
(What:="puppies", After:=rFound, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
rFound.EntireRow.Copy _
Destination:=Sheets("dogs").Cells(Rows.Count, 1).End(xlUp)(2, 1)
Next lloop
End Sub
[code/]
Here you go. Please mark the thread as SOLVED if it was
Sub GetPuppies() Dim shtBabies As Worksheet Dim shtDogs As Worksheet Set shtBabies = ThisWorkbook.Worksheets("babies") Set shtDogs = ThisWorkbook.Worksheets("dogs") Dim i, b, d As Long b = shtBabies.Cells.SpecialCells(xlCellTypeLastCell).Row d = shtDogs.Cells.SpecialCells(xlCellTypeLastCell).Row For i = 1 To b If shtBabies.Range("B" & i) = "puppies" Then d = d + 1 shtDogs.Range(d & ":" & d).Value = shtBabies.Range(i & ":" & i).Value End If Next End Sub
I dont know how to make that code do anything. I made 2 sheets (dogs & babies) and put in some data in the babies sheet and hit play. Nothing happened.
It doesnt really help even if it did work tho because I dont want to change my logic to find strings. I just want to make the loop work...
the code will search for the word puppies in column B then it will copy that row to the end of dogs sheet
I attached a file with the macro in it to test it
It works now. I had to reinstall my microsoft office suite to fix my Excel.
Thanks. I dont know how to mark this as SOLVED.
To mark your thread solved do the following:
- Go to the first post
- Click edit
- Click Advance
- Just below the word "Title:" you will see a dropdown with the word No prefix.
- Change to Solve
- Click Save
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks