Nested For Next Problem

kayza

Board Regular
Joined
Apr 29, 2015
Messages
61
Office Version
  1. 2007
Platform
  1. Windows
Hi.

I have a collection of data which consists of several items for which I will collect based on the criteria I have specified using the For Next statement.


and here is an example of the data :
AB
1UserID
2JhonA
3deanB
4billyB
5smithA
6lovelyA
7amberB
8LinaA
9joyB
10......

<tbody>
</tbody>




the results I want :
D
1dean
2billy
3amber
4joy

<tbody>
</tbody>




and here is the rough code that I use, which results are not what I want
Code:
For a = 2 To 10
If Cells(a, 2) = "B" Then
    For b = 1 To 4 
    Cells(b, 4) = Cells(a, 1)
Next b
End If
Next a



thanks in advance for your help
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
For a = 2 To 10
If Cells(a, 2) = "B" Then
Cells(a, 4) = Cells(a, 1)
End If
Next a
 
Upvote 0
Hi.
thanks for the quick response.
after I use your code, the placement results in accordance with the search line.


and I'm afraid this will not work in my worksheet. and I also plan to use the second for next statement by using step
 
Upvote 0
Dim a As Long, b As Long, RowCount As Long


RowCount = 2


For a = 2 To 10
If Cells(a, 2) = "B" Then
Cells(RowCount, 4) = Cells(a, 1)
RowCount = RowCount + 1
End If
Next a
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,290
Members
449,149
Latest member
mwdbActuary

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