Data Fill in Visual Basic

  • Thread starter Thread starter Carrie
  • Start date Start date
C

Carrie

I have a worksheet designed in columns. There are 0's, 1's & 2's in the
portion I am working with. I have set the 1 and 2's to coinside with a
calendar schedule. The 1 representing the start date and the 2 representing
the end date. In order to refresh my model I need the fill in all the 0's
between the 1 and 2 with 1's. (I may want to convert the 2 to a 1 as well,
not sure yet) Can anyone suggest a way to do this in visual basic? I have had
no luck and I do not want to do it with a formula.

Thx in advance
Carrie
 
Here is something you can start with: (this is a mod I got from
http://www.mvps.org/dmcritchie/excel/delempty.htm


Sub tester()
ZeroToOne (ActiveSheet.UsedRange) ' modify as needed to pass the range
you need changed to "1"
End Sub

Private Sub ZeroToOne(rng As Range)
Dim ix As Long
If rng Is Nothing Then
GoTo done
End If
For ix = rng.Count To 1 Step -1
If rng.Item(ix).Value = 0 Then
rng.Item(ix).Value = 1
End If
Next
done:
End Sub
 

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

Back
Top