loop - macro macro

bobaol

Board Regular
Joined
Jun 3, 2002
Messages
224
Office Version
  1. 365
  2. 2003 or older
Platform
  1. Windows
Hello,

I am doing a loop (kind of, i suppose) by using multiple macros. In macro27, i want to find "Problem_Closed", but if "Problem_Closed" does not exist, then exit the sub.

my problems lies in that "Problem_Closed" may exist once or may exist a thousand instances.

I am using Macro28 and Macro29 to repeat Macro27. This is very inefficient and takes a lot of time. But it does work.

is there a simpler way?


here is my code.....

Sub Macro27_find_cut_and_paste_to_Closed()
ActiveSheet.UsedRange
Application.Goto Reference:="R1C1"
If Cells.Find What:="Problem_Closed_OR_Service_Closed", After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True) Is Nothing Then
Exit Sub
End If
Cells.Find(What:="Problem_Closed_OR_Service_Closed", After:=ActiveCell, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=True).Activate
ActiveCell.Offset(0, 5).Range("A1").Select
Calculate
Selection.End(xlToLeft).Select
ActiveCell.Range("A1:AN1").Select
Selection.Cut
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveSheet.UsedRange
End Sub

Sub Macro28_repeat_Macro27_find_cut_and_paste_to_Closed()
Application.Run "Macro27_find_cut_and_paste_to_Closed"
Application.Run "Macro27_find_cut_and_paste_to_Closed"
Application.Run "Macro27_find_cut_and_paste_to_Closed"
Application.Run "Macro27_find_cut_and_paste_to_Closed"
End Sub
Sub Macro29_repeat_Macro27_find_cut_and_paste_to_Closed()
Application.Run "Macro28_repeat_Macro27_find_cut_and_paste_to_Closed"
Application.Run "Macro28_repeat_Macro27_find_cut_and_paste_to_Closed"
Application.Run "Macro28_repeat_Macro27_find_cut_and_paste_to_Closed"
Calculate
End Sub


thanks in advance.

- bobaol
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Off the top of my head, without looking too deeply at your code (have a toothache today, sorry) it seems you are filling a cell with a 'flag' to be found by another routine.

If that 'flag' exists only for the benefit of program flow, and doesn't need to be there otherwise, you could take the Sub that normally creates the flag, convert to Function, and have it return a Boolean.
 
Upvote 0

Forum statistics

Threads
1,218,756
Messages
6,144,304
Members
450,536
Latest member
DavidRankin

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