visual basic data fill?

C

Carrie

I have a very large range whereas I have 0's, 1's and 2's. The values
represent dates for classes in columns. (Example: Column D represents an
instructor and at some location down the column there is a 1 for start date
and a 2 for an end date. All other cells are 0's. see below)

When the 1 is found, I need all subsequent 0's between the 1 and 2 to be 1's
as well as the 2 to be replaced by a 1.

I cannot figure this out, can anyone help?

0
0
0
0
0
1
0
0
0
0
0
0
0
2
0
0
0
0
0
1
0
0
0
2
0
0
0
 
J

JE McGimpsey

Carrie said:
I have a very large range whereas I have 0's, 1's and 2's. The values
represent dates for classes in columns. (Example: Column D represents an
instructor and at some location down the column there is a 1 for start date
and a 2 for an end date. All other cells are 0's. see below)

When the 1 is found, I need all subsequent 0's between the 1 and 2 to be 1's
as well as the 2 to be replaced by a 1.

I cannot figure this out, can anyone help?

One way:

Dim rCell As Range
Dim nVal As Long
For Each rCell In Range("D2:D" & _
Range("D" & Rows.Count).End(xlUp).Row)
With rCell
If .Value = 0 Then
.Value = nVal
Else
nVal = 1 - nVal
End If
End With
Next rCell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top