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.
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,988
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,119,263
Messages
5,577,055
Members
412,763
Latest member
sienweiw
Top