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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,052
Office Version
  1. 365
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...?
 

Hoozits

Active Member
Joined
May 31, 2005
Messages
253
You are absolutely correct. Your suggested improvement worked like a charm. I hope you feel greatly appreciated for this because you are. Many thanks.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,620
Messages
5,832,734
Members
430,160
Latest member
a_majda

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
Top