Very simple VB programming


Posted by Johnny-C on July 13, 2001 9:28 AM


I just want to make a column with 64 1's, followed by 64 2's, and so on until I have 64 4's. The column would thus be 4096 rows long. I'm pretty naive with VB, and don't know how to program a cell's formula to accept a variable defined in the VB code (such as y=1, activecell.formula="=y"). Thanks!

Posted by Russell on July 13, 2001 9:53 AM

Try something like this (I used the dashes to indicate indenting since I don't know how to get code on here via HTML like some of these wizards -- replace them with spaces):

Dim intI as Integer
Dim intJ as Integer
Dim intCol as Integer

intCol = 1 '(or whatever column you would like to put these values in)

For intI = 1 to 4
----For intJ = 1 to 64

--------Cells(intJ * intI, intCol) = intI

----Next intJ
Next intI

Posted by Ben O. on July 13, 2001 10:14 AM

Johnny,

I'm not sure where you get 4096 from. 64 * 4 = 256. Anyway, here's some code you should be able to modify if it doesn't do what you want.

Sub CreateColumn()
myCol = 1
myRow = 1
For x = 1 To 4
For y = 0 To 63
Cells(y + myRow, myCol).Value = x
Next y
myRow = myRow + 64
Next x
End Sub


-Ben O.

Posted by Johnny-C on July 13, 2001 12:32 PM

I'm not sure where you get 4096 from. 64 * 4 = 256. Anyway, here's some code you should be able to modify if it doesn't do what you want. Sub CreateColumn() myCol = 1 myRow = 1 For x = 1 To 4 For y = 0 To 63 Cells(y + myRow, myCol).Value = x Next y myRow = myRow + 64 Next x
Sorry about that; I meant up until I have 64 64's. Thanks for the code, though! :

Posted by Russell on July 13, 2001 3:12 PM

My (simpler) code will work for 64 "64's" too, just change the first "1 to 4" to "1 to 64":

Try something like this (I used the dashes to indicate indenting since I don't know how to get code on here via HTML like some of these wizards -- replace them with spaces):

Dim intI as Integer
Dim intJ as Integer
Dim intCol as Integer

intCol = 1 '(or whatever column you would like to put these values in)

For intI = 1 to 64
----For intJ = 1 to 64

--------Cells(intJ * intI, intCol) = intI

----Next intJ
Next intI

Have fun,

Russell



Posted by Johnny-C on July 13, 2001 4:55 PM

Thanks, Russell; I actually did use your code from the first reply. I wish my job required more use of VB. I'd be forced to learn it well. As it stands, I'm kind of a blind fool! Thanks for the help.