Show result of loop after each iteration

Hoozits

Active Member
Joined
May 31, 2005
Messages
253
I am using a for...next loop and would simply like to display the result of that loop in a cell on a spreadsheet at each iteration. Any help would be greatly appreciated. Here is an example:

for j = 101 to 111
for k = 1 to 100
if cells(k,3)="Mr. Excel" then
cells(j, 1)=cells(k,2)
end if
next k
next j

The problem I am having is that only the last value for k is being used to produce results in cells(j,1). The j-loop works fine, but the k-loop is not. Thanks in advance for any help.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I don't think you need the j loop.

Code:
j = 101
for k = 1 to 100 
if cells(k,3)="Mr. Excel" then 
cells(j, 1)=cells(k,2) 
j = j + 1
end if 
next k

But, why would j only go from 101 to 111? Or is there Mr. Excel only in every 10th row or similar...?
 
Upvote 0
You are absolutely correct. Your suggested improvement worked like a charm. I hope you feel greatly appreciated for this because you are. Many thanks.
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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