Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing 0 and 1 2

Status
Not open for further replies.

FJAY

Programmer
Apr 23, 2003
106
0
0
CA
I'm trying to print 0 and 1 in a range of cell but I can't get it work: I keep getting all 0 values

Dim myRange As Range, i As Integer, b As Integer

ActiveSheet.Range("A1:a10").Select

i = 1
For Each myRange In Selection.Cells
b = i - 1
myRange.Value = b
i = b + i
Next
 
Hi FJAY, try the below, simply swap the 0 and 1 depending on whether you want the list to start with a 0 or 1:
Code:
Sub test()
Dim myRange As Range
ActiveSheet.Range("A1:A10").Select
For Each c In Selection.Cells
  a = c.Row Mod 2
  If a = 0 Then
    c.Value = 1
  Else
    c.Value = 0
  End If
Next
End Sub
 
hi,
Code:
Sub test()
   For Each c In ActiveSheet.Range("A1:A10")
      With c
         .Value = .Row Mod 2
      End With
   Next
End Sub


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Molby, it worked fine. What about of I want to print 0,0,1,1,2,2,3,3 and so on in the same range. Thanks.
 
Code:
Sub test()
   i = -1
   For Each c In ActiveSheet.Range("A1:A10")
      With c
         If .Row Mod 2 = 1 Then i = i + 1
         .Value = i
      End With
   Next
End Sub


Skip,
[sub]
[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top