Make it better


Posted by Jonas Linder on May 26, 2001 5:45 AM

I'm would like to do a for...to funktion of this code.

Public Sub SkrivPlacering()
Worksheets("Blad1").Range("C1") = 1
Worksheets("Blad1").Range("c2") = 2
Worksheets("Blad1").Range("c3") = 3
Worksheets("Blad1").Range("c4") = 4
Worksheets("Blad1").Range("c5") = 5
Worksheets("Blad1").Range("c6") = 6
Worksheets("Blad1").Range("c7") = 7
Worksheets("Blad1").Range("c8") = 8
End Sub

the numbers ain't the problem. The cells are.. Thx

Posted by Dax on May 26, 2001 7:13 AM

Rather than use the A1 style of referencing cells, it might be easier to use the numeric styles e.g. Cells(3,2) where 3 is the 3rd row and 2 is the 2nd column. It makes it easier when looping through cells.

Public Sub SkrivPlacering()
Dim Rowcounter As Long

For Rowcounter = 1 To 8
Worksheets("Blad1").Cells(Rowcounter, 3) = Rowcounter
Next Rowcounter

End Sub


Ain't that better?

Regards,
Dax.

Posted by Jonas Linder on May 26, 2001 7:28 AM

Well much better.... I'm a newbee, thx for the help;-)


Posted by Duncan on May 26, 2001 7:30 AM


Ain't this even better? (no looping!)

Public Sub SkrivPlacering()
With Range("C1")
.Value = 1
.AutoFill Destination:=Range("C1:C8"), Type:=xlFillSeries
End With
End Sub




Posted by Jonas Linder on May 26, 2001 7:41 AM


I Like both of them;-)
But to not use a loop is even nicer(its a bigger load for the CPU):-)
Thx ones more