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.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
> go to RPTDT

Range("RPTDT").Select

> GO DOWN the rows by the number in range("rptcount")

Range("RPTDT").Offset(Range("rptcount").Value)

> Compare the contents of the cell selected after going down by a number of rows.

compare with what ?
 
Upvote 0
Thank you very much for your post...i was trying to use the offset property but it didnt work as i was not writing it correctly...so this helps a lot:)

i need to compare the value of the active cell after going by the number in range("rptcount")...to another named cell range ("RPTCHK")
IF ACTIVECELL > RPTCHK
THEN CALL ANOTHER MACRO CALLED rptchk2
ELSE add one to the ("rptcount") so it goes to the next cell if the first condition is not met.

The spreadsheet i working no is quite huge there are a lot of loops leading to each other.

Will use the posts to get started now:)...thank you.
 
Upvote 0
This is what i have come up with but it gives the error in the first statement when i try to set the ("RPTCNT") TO 0...as the value for RPTCNT has to be updates everytime it goes through the loop( if the first if is not satisfied)

Sub rptloop()

Set RPTCNT = 1

For i = 1 To Range("CURCNT")
Range("PYRCHK").Select
ActiveCell.FormulaR1C1 = "=0"
Range("RPTDT").Select
Range("RPTDT").Offset (Range("RPTCNT").Value)

If ActiveCell.Value > [RPTCHK] Then
Call RPTCHK2
ElseIf [RPTCNT] >= [CURCNT] Then
Call QTRPT
Else
RPTCNT = RPTCNT + 1
End If
Next

End Sub

Any suggestions???
navya
 
Upvote 0
SO when i say RPTCNT =1 and then later i write RPTCNT= RPTCNT + 1 , WILL IT increment it by one if conditon is not met?

I have another question:
When i use the Offset property it gives me an error is there anything wrong with the statement i used??(IT GIVES ME AN ERROR SAYING INVALID USE OF PROPERTY)
Range("RPTDT").Offset(Range ("RPTCNT").Value)

Thank you,
Navya
 
Upvote 0
On 2002-09-11 14:30, navyaa wrote:
SO when i say RPTCNT =1 and then later i write RPTCNT= RPTCNT + 1 , WILL IT increment it by one if conditon is not met?

Yes

I have another question:
When i use the Offset property it gives me an error is there anything wrong with the statement i used??(IT GIVES ME AN ERROR SAYING INVALID USE OF PROPERTY)
Range("RPTDT").Offset(Range ("RPTCNT").Value)

if you read the help text on offset you see it requires row and column values:
.OFFSET(ROW,COLUMN)


Thank you,
Navya

Your Welcome JRN
 
Upvote 0
i tried to change the offset line to include the column but it gives an error again:

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

any ideas as to what im doing wrong and what i should be doing instead??

THANK YOU...navya
 
Upvote 0

Forum statistics

Threads
1,213,561
Messages
6,114,316
Members
448,564
Latest member
ED38

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