none
I need to be able to set the column width for a range of cells in a for each loop. RRS feed

  • Question

  • For Each c In Worksheets("Get data").Range("A2:AO250").Cells ' This works

    I need to be able to set the column width for a range of cells in a for each loop.

    'For Each c In Worksheets("Get data").Range(Cells(2, 1), Cells(250, 10)).Cells   ' why does this not work and how can i make this statment work so i can use a variable as the column width.

    Monday, October 3, 2011 10:07 PM

Answers

  • How about:

     

    Sub demo()
    Dim R As Range, c As Range
    Set R = Worksheets("Get data").Range(Cells(2, 1), Cells(250, 10))
    MsgBox R.Address

    For Each c In R
        c.EntireColumn.ColumnWidth = 3
    Next
    End Sub


    gsnu201109
    Monday, October 3, 2011 11:06 PM
    Moderator