+ Reply to Thread
Results 1 to 5 of 5

variable for columns(??).property

  1. #1
    Neal Zimm
    Guest

    variable for columns(??).property

    With your help a while ago I was able to 'vary' the rows being procecessed.
    the rows procedure works, I could not get the columns procedure to work.
    sub variable_rows()
    ''' this works
    Dim first, last, hiderange
    first = 13
    last = 15
    hiderange = first & ":" & last
    Rows(hiderange).Hidden = True
    End Sub

    Sub variable_columns()
    '''this does not work, object error
    Dim first, last, workrange
    first = 13
    last = 15
    workrange = first & ":" & last
    Columns(workrange).ColumnWidth = 20
    End Sub

    Help Please.
    thanks.


    --
    Neal Z

  2. #2
    Ron de Bruin
    Guest

    Re: variable for columns(??).property

    Try this Neal

    Sub variable_columns1()
    Dim first As Integer, last As Integer
    first = 13
    last = 15
    Range(Cells(1, first), Cells(1, last)).ColumnWidth = 20
    End Sub

    Or to hide

    Sub variable_columns2()
    Dim first As Integer, last As Integer
    first = 13
    last = 15
    Range(Cells(1, first), Cells(1, last)).EntireColumn.Hidden = True
    End Sub

    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "Neal Zimm" <[email protected]> wrote in message news:[email protected]...
    > With your help a while ago I was able to 'vary' the rows being procecessed.
    > the rows procedure works, I could not get the columns procedure to work.
    > sub variable_rows()
    > ''' this works
    > Dim first, last, hiderange
    > first = 13
    > last = 15
    > hiderange = first & ":" & last
    > Rows(hiderange).Hidden = True
    > End Sub
    >
    > Sub variable_columns()
    > '''this does not work, object error
    > Dim first, last, workrange
    > first = 13
    > last = 15
    > workrange = first & ":" & last
    > Columns(workrange).ColumnWidth = 20
    > End Sub
    >
    > Help Please.
    > thanks.
    >
    >
    > --
    > Neal Z




  3. #3
    Vasant Nanavati
    Guest

    Re: variable for columns(??).property

    Try:

    first = "M"
    last = "O"

    BTW, you should declare the correct data types for your variables; i.e.:

    Dim first As String, last As String, workrange As String

    --

    Vasant


    --

    Vasant



    "Neal Zimm" <[email protected]> wrote in message
    news:[email protected]...
    > With your help a while ago I was able to 'vary' the rows being

    procecessed.
    > the rows procedure works, I could not get the columns procedure to work.
    > sub variable_rows()
    > ''' this works
    > Dim first, last, hiderange
    > first = 13
    > last = 15
    > hiderange = first & ":" & last
    > Rows(hiderange).Hidden = True
    > End Sub
    >
    > Sub variable_columns()
    > '''this does not work, object error
    > Dim first, last, workrange
    > first = 13
    > last = 15
    > workrange = first & ":" & last
    > Columns(workrange).ColumnWidth = 20
    > End Sub
    >
    > Help Please.
    > thanks.
    >
    >
    > --
    > Neal Z




  4. #4
    Neal Zimm
    Guest

    Re: variable for columns(??).property

    Thanks Vasant,
    In my real code I dim the vars properly. For this example, since I use
    option explicit I just dimmed them as varants for 'speed of typing'.
    Also, because I use a lot of variables for columns and rows, i'm in the
    habit of using the numbers rather than letters so I don't have to convert
    a 1 into an "A".
    Thanks again,
    Neal


    "Vasant Nanavati" wrote:

    > Try:
    >
    > first = "M"
    > last = "O"
    >
    > BTW, you should declare the correct data types for your variables; i.e.:
    >
    > Dim first As String, last As String, workrange As String
    >
    > --
    >
    > Vasant
    >
    >
    > --
    >
    > Vasant
    >
    >
    >
    > "Neal Zimm" <[email protected]> wrote in message
    > news:[email protected]...
    > > With your help a while ago I was able to 'vary' the rows being

    > procecessed.
    > > the rows procedure works, I could not get the columns procedure to work.
    > > sub variable_rows()
    > > ''' this works
    > > Dim first, last, hiderange
    > > first = 13
    > > last = 15
    > > hiderange = first & ":" & last
    > > Rows(hiderange).Hidden = True
    > > End Sub
    > >
    > > Sub variable_columns()
    > > '''this does not work, object error
    > > Dim first, last, workrange
    > > first = 13
    > > last = 15
    > > workrange = first & ":" & last
    > > Columns(workrange).ColumnWidth = 20
    > > End Sub
    > >
    > > Help Please.
    > > thanks.
    > >
    > >
    > > --
    > > Neal Z

    >
    >
    >


  5. #5
    Neal Zimm
    Guest

    Re: variable for columns(??).property

    Of course, I use the range syntax a lot, just didn't think about these
    properties.
    thanks again,
    Neal


    "Ron de Bruin" wrote:

    > Try this Neal
    >
    > Sub variable_columns1()
    > Dim first As Integer, last As Integer
    > first = 13
    > last = 15
    > Range(Cells(1, first), Cells(1, last)).ColumnWidth = 20
    > End Sub
    >
    > Or to hide
    >
    > Sub variable_columns2()
    > Dim first As Integer, last As Integer
    > first = 13
    > last = 15
    > Range(Cells(1, first), Cells(1, last)).EntireColumn.Hidden = True
    > End Sub
    >
    > --
    > Regards Ron de Bruin
    > http://www.rondebruin.nl
    >
    >
    > "Neal Zimm" <[email protected]> wrote in message news:[email protected]...
    > > With your help a while ago I was able to 'vary' the rows being procecessed.
    > > the rows procedure works, I could not get the columns procedure to work.
    > > sub variable_rows()
    > > ''' this works
    > > Dim first, last, hiderange
    > > first = 13
    > > last = 15
    > > hiderange = first & ":" & last
    > > Rows(hiderange).Hidden = True
    > > End Sub
    > >
    > > Sub variable_columns()
    > > '''this does not work, object error
    > > Dim first, last, workrange
    > > first = 13
    > > last = 15
    > > workrange = first & ":" & last
    > > Columns(workrange).ColumnWidth = 20
    > > End Sub
    > >
    > > Help Please.
    > > thanks.
    > >
    > >
    > > --
    > > Neal Z

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1