+ Reply to Thread
Results 1 to 10 of 10

Selecting range using .range. But can you do same selection using .columns

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Selecting range using .range. But can you do same selection using .columns

    I know how to select a range of cells using code similar to the following:

    Set myinputfile = Workbooks("Dav_16Jun2011.xlsx").Worksheets("Sheet1")
    myinputfile.Range("A1:A" & alphacol(lst_row)).Select
    i have a function called alphacol which converts lst_row number to character equivalent.

    What i was wondering is .......is there a way to select range using the .columns

    I know i can select individual cells using .columns ....such as

    myinputfile.Columns(lst_row, 1).Select
    But i dont know how to select a range using the column method.
    Last edited by welchs101; 07-01-2011 at 01:38 PM.

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Re: Selecting range using .range. But can you do same selection using .columns

    ok....i actually had an error in my first code but this error should not effect my question

    corrected code:
    myinputfile.Range("A1:A" & lst_row).FillDown

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Re: Selecting range using .range. But can you do same selection using .columns

    ok....showing my ignorance..........its not .columns but rather .cells i think that i am referring to.

    For example: How to select a range using the .cells method

    myinputfile.Cells(lstrow, 1).Select

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Re: Selecting range using .range. But can you do same selection using .columns

    romperstomper...........did not see your reply before i posted mine..........your really on top of things. sorry for the confusion.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Selecting range using .range. But can you do same selection using .columns

    None of that code will work. I suspect you are thinking of the Cells property rather than Columns?
    Remember what the dormouse said
    Feed your head

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Selecting range using .range. But can you do same selection using .columns

    The last code you posted will work, assuming the right sheet is selected first.
    However, it is very rarely necessary to actually select cells in code.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Selecting range using .range. But can you do same selection using .columns

    You don't really need to select a Range

    Set myinputfile = Workbooks("Dav_16Jun2011.xlsx")
    myinputfile.Worksheets("Sheet1").Range("A1:A" & alphacol(lst_row)).Select
    I don't know what this is

    alphacol(lst_row
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Re: Selecting range using .range. But can you do same selection using .columns

    hi guys,

    What i want to do is filldown some data from cell 1 to say cell 10,000. I know the value i want to filldown its a constant.

    Normally i do the filldown such as this:

    myinputfile.Range("A2:A" & lst_row).FillDown
    i was just curious if there was a way to do the same thing using a .cell


    This is kind of a bad example but usually when i have to select ranges using the .range method i have to specify a col letter and i was wondering if there was a way to get around this ...........thoguht may be about the .cells.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,298

    Re: Selecting range using .range. But can you do same selection using .columns

    You can use resize, or use Cells with Range:
    Cells(1, 1).Resize(1000, 1).Value = "blah"
    Range(Cells(1, 1), cells(1000,1)).value = "blah"

  10. #10
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,669

    Re: Selecting range using .range. But can you do same selection using .columns

    thanks. I like the resize option for this answer.

    Thanks.

+ 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