How to end loops at certain row

Linda21

New Member
Joined
Aug 2, 2010
Messages
38
I want the following code to stop at row 3000. Where can I insert the code and what should it be?

I am looping through data in column 1 until I find TRANSACTION SUMMARY. Then I pass a specified value through to a variable and post to column 17 as long as column 1 is not ABC. Once column 1 is ABC, it exits the do and starts over with the first do loop, I want the code to find the next TRANSACTION SUMMARY and so on. All that works just fine. I can't figure out how to stop this. Also, I admit this code isn't very pretty...I am a beginner. Thank you.

Code:
Sub UpdateFundName()
StartRow = 1
TranCodeCol = 1
FundColumn = 17
EndRow = 1
 
CurrentCell = Cells(StartRow, TranCodeCol)
Do Until CurrentCell = "TRANSACTION SUMMARY " 
CurrentCell = Cells(StartRow, TranCodeCol) 
If CurrentCell = "TRANSACTION SUMMARY " Then
 
 
StartRow = StartRow + 1
 
Fund = Cells(StartRow, TranCodeCol) 
StartRow = StartRow + 10 
Do 
CurrentCell = Cells(StartRow, TranCodeCol) 
If CurrentCell = "ABC" Then Exit Do
CurrentCell = Cells(StartRow, TranCodeCol)
 
Cells(StartRow, FundColumn).Value = Fund
StartRow = StartRow + 1
CurrentCell = Cells(StartRow, TranCodeCol)
 
If CurrentCell = "ABC" Then Exit Do
 
Loop
 
End If
 
StartRow = StartRow + 1
 
Loop
 
End Sub
 
Last edited by a moderator:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you are always wanting to stop at 3000, why not use a for loop?

Something like: For i = 1 To 3000
 
Upvote 0
I tried that earlier, but because I have the 2 do loops, I could not get the code to work.

Where would I place the for/next code? I tried it surrounding both loops, but it doesn't work. It continues to say it is 'running'.
 
Upvote 0

Forum statistics

Threads
1,203,434
Messages
6,055,346
Members
444,781
Latest member
rishivar

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