loop - macro macro

bobaol

Board Regular
Joined
Jun 3, 2002
Messages
188
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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,214,897
Messages
6,122,151
Members
449,068
Latest member
shiz11713

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