Macro works alone, but not in a loop.

Joxon

Board Regular
Joined
Nov 3, 2008
Messages
56
Hi everyone!

I have a problem.
When I run Macro4() below it works perfect.
But when I try to run it in a loop in macro3() I get problems. It jumps to cells it should not and behave strange. Any guesses why?


Sub Macro3()
Dim i As Integer
For i = 1 To 20
Call Macro4
Next i
End Sub

Sub Macro4()
Call Macro1
Call Macro2
End Sub

Thank you in advance.

Regards
Joxon
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Sub Macro1()
ActiveCell.Offset(0, 6).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, -6).Range("A1").Select
End Sub

Sub Macro2()
Application.SendKeys ("%=~")
End Sub
 
Upvote 0
Why not just have this:

Sub Macro3()
Dim i As Integer
For i = 1 To 20
Call Macro1
Call Macro2
Next i
End Sub

Jesse
 
Upvote 0
In the loop macro It jumps like 80 rows and puts all sums after one another.
Really strange?
 
Upvote 0
2 things, 1st off what exactly are you trying to achieve? And 2nd, I think its jumping down so far because you might have your active cell starting wrong, I would recommend adding in a line to say your starting position like this :

Sub Macro3()
Dim i As Integer
Range("A1").Select
For i = 1 To 20
Call Macro1
Call Macro2
Next i
End Sub

Jesse
 
Upvote 0
I have a dynamic list with subtotals. And I want to sum each subtotal.

12
5
Sum(17)
2
50
40
Sum(92)
2
sum(2)

and so on. The list is different each time. The macro should jump down to each sum() and sum the above numbers.

I still get the same fault even when i select a range.

Regards

jox
 
Upvote 0
When I run the code I get the sums in column A, but it seems to not be filling the brackets with any information. What do you have these defined as?

%=~

Jesse
 
Upvote 0
%=~ is the command for autosum i Excel. But you have to exit the macro editor for it to work.

More Idees?
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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