GOING DOWN BY A SPECIFIC NO. in a loop -IN EXCEL

navyaa

Board Regular
Joined
Jul 7, 2002
Messages
223
I need to write a loop where i have start with selecting a cell and then going down the column based on the value in another cell.

eg. 1) go to RPTDT
2) GO DOWN the rows by the number in range("rptcount")
3)Compare the contents of the cell selected after going down by a number of rows.


How can i write this in VB...any suggestions?

Thank you,
navya.
 
Apologies to Jim for butting in here.

RPTCNT is the counter so I do not think that Range("RPTCNT") exists.

So should the code be?

Range("RPTDT").Offset(RPTCNT,0)
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Thats what i wanted to confirm...BECAUSE RPTCNT a named cell range in the sheet and when the loop is run i want the value in that cell to be incremented with the loop so will the code I am using do that.

I got the Offset to work:
Range("RPTDT").Select
ActiveCell.Offset(rowOffset:=[Range("RPTCNT").Value], columnOffset:=0).Activate

Dont know what i was doing wrong before.

Thank you for your help....
 
Upvote 0
So do you need?

Code:
Set RPTCNT = Range("RPTCNT")
RPTCNT.Value = 1
'*** More of your existing code ***
RPTCNT.Value = RPTCNT.Value + 1

Currently you don't seem to be updating the counter in the worksheet.
 
Upvote 0
Sub rptloop()

Set RPTCNT = Range("RPTCNT")
RPTCNT.Value = 1

For i = 1 To Range("CURCNT")
Range("PYRCHK").Select
ActiveCell.FormulaR1C1 = "=0"
Range("RPTDT").Select
ActiveCell.Offset(rowOffset:=[Range("RPTCNT").Value], columnOffset:=0).Activate
If ActiveCell.Value > [RPTCHK] Then
Call RPTCHK2
ElseIf [RPTCNT] >= [CURCNT] Then
Call QTRPT
Else
RPTCNT.Value = RPTCNT.Value + 1
End If

Next


End Sub

THIS IS MY UPDATED CODE NOW AFTER MAKING ALTERATIONS ACCORING TO YOUR POST. I KNEW THERE WAS SOMETHING WRONG BUT DIDNT KNOW HOW TO UPDATE THE VALUE OF THE CELL LIKE A COUNTER.
does this look fine now?
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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