+ Reply to Thread
Results 1 to 9 of 9

Columns("A:A").Select gives error...

  1. #1
    Registered User
    Join Date
    07-27-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Columns("A:A").Select gives error...

    Run-time error '1004':

    Application-defined or object-defined error.


    -----------------------------------------------------

    I have one main macro that creates new workbooks, puts data in them based on at text file, then formats them how they need to be (Cell data format, coloring, spacing, etc). For some reason Columns("A:A").Select gives me an error. Is this because I am creating a workbook from code? If so, how do I make it work?

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Columns("A:A").Select gives error...

    It sounds more like a coding error, but to know that we would need to see the code....
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Columns("A:A").Select gives error...

    There's nothing wrong with the syntax -- depends on the context, I guess.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-27-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Columns("A:A").Select gives error...

    Fix:

    Worksheets(1).Columns("A:A").Select

    ...

    weird.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Columns("A:A").Select gives error...

    Methinks the worksheet is hidden. You can't select something on a hidden worksheet.

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

    Re: Columns("A:A").Select gives error...

    If your code is in a worksheet module, then an unqualified reference to Columns("A:A") would always refer to that sheet. If that sheet isn't the active one, you can't select a range on it. Specifying the sheet, assuming Worksheets(1) is active, cures the problem.
    Everyone who confuses correlation and causation ends up dead.

  7. #7
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Columns("A:A").Select gives error...

    ...and this is why it is usually helpful if the OP posts more than just a single fraction of code when having a problem

  8. #8
    Registered User
    Join Date
    05-21-2021
    Location
    Phoenix, AZ
    MS-Off Ver
    Current
    Posts
    3

    Re: Columns("A:A").Select gives error...

    I had an issue selecting a column, via VBA, when one of the rows was merged.
    In my case it was row 1, not sure if that played a role or not.
    VBA insisted on selecting multiple columns for Columns("A:A").Select.
    Screwed around a while to find this issue.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,692

    Re: Columns("A:A").Select gives error...

    @RayInAZ
    When you merge cells, you risk:
    Losing the ability to properly sort data.
    Losing the ability to run VBA programming code on your data because it doesn't handle merged cells very well, and a significantly larger amount of code may need to be written to cover the merged cells.
    and
    https://edu.gcfglobal.org/en/excel-t...rging-cells/1/

+ 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