Loop or If Statement Issue - looping wrong number of times

JulieSB

New Member
Joined
Jun 4, 2013
Messages
14
Hi - I am trying to loop through my code below Range("MonthCount2") times - which we'll say is 10.

Within this loop, I have an IF statement, which contains a loop of "Multival" times - which for the first loop through is 2.

My code does what i want (i.e. pastes the selection MultiVal times) but only does this for two selections. Does not continue MonthCount2 times.

Do I have my IF statement or loop in the wrong place? Am I missing something? Any help appreciated:

For x = 1 To Range("MonthCount2")
Sheets("Balance Sheet Calculations").Select
Cells(intRowNum, intColNum).Select
Range(ActiveCell, ActiveCell.Offset(0, 8)).Select

'columns being copied
Selection.Copy


Sheets("Funding").Select
Range("StartIntercompanyPaste").Select

'start of the short term funding sheet
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Calculate
NeedVal = ActiveCell.Offset(0, 7).Value
MsgBox NeedVal
ActiveCell.Offset(1, 0).Select

If NeedVal * -1 > intIncrement Then
MultiVal = NeedVal / intIncrement * -1
ActiveCell.Offset(-1, 7) = intIncrement * -1
Range(ActiveCell.Offset(-1, 0), ActiveCell.Offset(-1, 8)).Select
Selection.Copy
For y = 1 To MultiVal
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(1, 0).Select
Next y
End If

Call New_Cash_Optimization

intRowNum = intRowNum + 1

Next x
 
Is MonthCount2 a string variable? If so, you don't need the " " around it.
 
Last edited:
Upvote 0
monthcount2 is a range that contains a number. MonthCount2 does not appear to be the problem, it was functional before i added the IF statement
 
Upvote 0
monthcount2 is a range that contains a number. MonthCount2 does not appear to be the problem, it was functional before i added the IF statement

I only asked because I can't seem to duplicate a working loop if I set it up the way your outer loop is.

This works for me though(A1 contains 10):
Code:
Sub TestLoops()
Dim CountA As Range
Dim i As Long
Set CountA = Range("A1")
For i = 2 To CountA.Value
Worksheets("Sheet1").Range("B" & i).Value = "X"
Next
End Sub
 
Upvote 0

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