Cannot make small code work...I think someone can suggest where i'm doing it wrong. :)

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi! Happy Saturday to all! :biggrin:

The one right below is not working....


Code:
Sub try()
Dim ws As Worksheet
For Each ws In Worksheets
  ws.Range("A2").FormulaR1C1 = "1"
  ws.Range("A2").AutoFill Destination:=Range("A2:A500"), Type:=xlFillSeries
  ws.Range("A2:M500").HorizontalAlignment = xlCenter
  
Next
End Sub



This is working (the code below) but i want to see if someone can make the code shorter or suggest something better ....as 'm still learning :)
Code:
Sub DoToAll()
Dim ws As Worksheet
For Each ws In Worksheets
ws.Range("A1") = "com1"
ws.Range("B1") = "com2"
ws.Range("C1") = "com3"
ws.Range("D1") = "com4"
ws.Range("E1") = "com5"
ws.Range("F1") = "com6"
ws.Range("G1") = "Status%"
ws.Range("H1") = "Status11"
ws.Range("I1") = "Status23"
ws.Range("J1") = "Status12"
ws.Range("K1") = "Status4"
ws.Range("L1") = "Status2"
ws.Range("M1") = "Status"
ws.Range("A1:M1").Font.Bold = True
ws.Range("A1:M1").Font.Color = vbWhite
ws.Rows("1:1").RowHeight = 22.5
ws.Range("A1:M1").Interior.ThemeColor = xlThemeColorLight2
ws.Range("A1:M1").HorizontalAlignment = xlCenter
ws.Range("A1:M1").VerticalAlignment = xlCenter
Next
End Sub

Thanks Pedie;)
 
For the first, what are you trying to do?

For the second,
Code:
Sub DoToAll()
    Dim wks         As Worksheet
    For Each wks In Worksheets
        With wks.Range("A1:M1")
            .Value = Array("com1", "com2", "com3", "com4", "com5", "com6", _
                           "Status%", "Status11", "Status23", "Status12", _
                           "Status4", "Status2", "Status")
            .Font.Bold = True
            .Font.Color = vbWhite
            .RowHeight = 22.5
            .Interior.ThemeColor = xlThemeColorLight2
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
    Next
End Sub
 
Last edited:
Upvote 0
Try

Code:
Sub try()
Dim ws As Worksheet
For Each ws In Worksheets
    With ws
        .Range("A2").Value = 1
        .Range("A2").AutoFill Destination:=.Range("A2:A500"), Type:=xlFillSeries
        .Range("A2:M500").HorizontalAlignment = xlCenter
    End With
Next
End Sub
 
Upvote 0
That was Quick & both code works perfectly. Thanks alot!

Happy a great weekend guys!!
Bye Vog!;)
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top