+ Reply to Thread
Results 1 to 7 of 7

Selecting from a column by name

  1. #1
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,051

    Selecting from a column by name

    Okay, I always get confused on this:

    My headers exist in Row 12.
    An autofilter is applied.
    There's a column with the header "YTD Expense\Avg FTE", which constantly moves around as columns are added and removed from the sheet (but it should always be on row 12). I'll call that my Target column.

    There MAY or MAY NOT be data under the pertinent data in my target column (if so, it will be separated by at least two blank lines).

    I want to copy the visible cells in my target column, under (not including) the header, to the bottom of the filtered data, above any data that may be under it.

    Any takers on how to do this? I can do all the copying, I just don't know how to zero in on my desired target column and my desired data within it.

    Any help is greatly appreciated.

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,156

    Re: Selecting from a column by name

    hi jomili, i did a little recording & adding of variables to come up with this:

    Please Login or Register  to view this content.
    from what i understand, there are cells separated from the filtered data below you dont want to copy? for eg if the header is in G12, & data is from G15 to G20. There can be some more data in G30:G32 you dont want? my code will copy from G13 to G20 & end there

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,051

    Re: Selecting from a column by name

    Benishiryo,

    It looks like your code should work just fine, but the workbook I'm trying it in is made be another group. It's protected in various ways, and some macros don't behave the way they should. I'm getting an error at the Range("A1").select line. I made a cheap little macro to test just that:
    Please Login or Register  to view this content.
    Running that (or your code) give me a run-time 1004 error.

    I can manually select A1, but don't seem to be able to do it with a macro. Any thoughts? I can break the password and unprotect the sheet, but don't know the password to reprotect it, and this is a workbook that's updated by various people, so all the protections have to remain in place.

  4. #4
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,051

    Re: Selecting from a column by name

    Benshiryo,
    I made a change; I've now unprotected the worksheet, so I can apply your macro, and I'm getting a runtime error 91 "Object Variable or With block variable not set" on the "Cells.Find" line. Below is my macro as I've got it configured so far.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Selecting from a column by name

    Hmm?

    Maybe you don't need to use a macro for this.

    Try using dynamic named ranges

    Name = "Target"
    Refers to:=
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Name = "TargetColumn"
    Refers to:=
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    You can now do any calcs regardless of where the "Target" is in row 12,and how long it turns out to be.

    See this workbook
    Sheet2 copies the column to a fixed site, where you can filter it for non-blanks if you still need to.
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  6. #6
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,051

    Re: Selecting from a column by name

    I've actually tackled the problem from another angle; instead of trying to do anything in the workbook, I'm just doing a VLookup to it. But that also presents difficulties, as I have to determine which column in the workbook my target column is at. I can achieve this by first opening the workbook, then doing a VLookup to it, then closing it. I'd like to be able to do it without the opening/closing. Below is my code thus far:
    Please Login or Register  to view this content.
    Last edited by jomili; 11-20-2012 at 01:02 PM. Reason: Left in unneeded select statement.

  7. #7
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    4,051

    Re: Selecting from a column by name

    Marcol,

    Sorry I didn't reply directly to your solution. The workbook/sheet is protected; when I try to add named ranges the whole Name Manager dialogue is greyed out.

+ 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