cut copy paste to a new location on same WB via loop

AussieSteve

New Member
Joined
Dec 28, 2017
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone.
So far my macro does all that I want except an error at the end of the macro ,which is my lack of understanding of how to end the macro when it's finished. The error is run time 1004. What the macro does is search for a piece of Txt using Find, it then cuts the data pastes it into another column and runs through the rest of the column doing the same thing. The part that causes the error is when excel continues to apply the Find to the first cut and paste, and that data is about to cut pasted but it can not go on at that point. Yes I know it needs an Exit from the Do Loop but I do not know how to get excel to stop the final search.
Thanks for any help on this situation.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I would be helpful if you supplied your code ;)
 
Upvote 0
Reply to Fluff.
Here is the macro in full, I use the "find what" to locate the cell with data I want to cut paste then the loop does the rest of the column, the error happens at the end of the loop. I have been experimenting with VBA for about 5 months so still new with it. By the way is it possible to do multiple word searches in the same macro?


[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub DoLoop()
'still comes up with a run time error 1004
'Application defined or object defined error
'but it works ok''''''''''''''''
Dim Rng As Range
Set Rng = Range("E1", Range("E2").End(xlDown))
Dim c As Range
Set c = Rng.Find(What:="MarketPlace")
Application.ScreenUpdating = False
Cells.Find(What:="MarketPlace", LookAt:=xlWhole, _
SearchDirection:=xlDown = True, MatchCase:= _
True, SearchFormat:=False).Activate
Do
ActiveCell.Offset.Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(5, -3).Range("A1").Select
ActiveSheet.Paste
Cells.FindNext(After:=ActiveCell).Activate
If ActiveCell = ActiveCell.Offset(5, -3) Then Exit Do
Loop
Application.ScreenUpdating = True
End Sub[/FONT]
 
Upvote 0
How about
Code:
Sub DoLoop()
'still comes up with a run time error 1004
'Application defined or object defined error
'but it works ok''''''''''''''''
   Dim Rng As Range
   Set Rng = Range("E1", Range("E" & Rows.Count).End(xlUp))
   Dim c As Range
   Set c = Rng.Find("MarketPlace", , , xlWhole, , xlNext, True, , False)
   Application.ScreenUpdating = False
   Do While Not c Is Nothing
      c.Resize(, 3).Copy c.Offset(5, -3)
      c.Resize(, 3).ClearContents
      Set c = Rng.FindNext(c)
   Loop
   Application.ScreenUpdating = True
End Sub
 
Upvote 0
Reply to Fluff.
I guess this is why you are a MrExcel MVP Moderator. The code is working perfectly, now I can compare your code to my shambles and learn something.
Again thank you and to the many people on this site that help people like me.....
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top