+ Reply to Thread
Results 1 to 11 of 11

VBA for searching for a value/highlight/copy

  1. #1
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    VBA for searching for a value/highlight/copy

    I'm looking to create a macro that looks down a specified column for 4 different values (something like A, B, C, D) and if those values are there for it to highlight and copy the rows.

    Anyone have any idea how to make this?

  2. #2
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA for searching for a value/highlight/copy

    Do you have any more details? Copy the column to where?

    A sample workbook maybe the best way to help here.

  3. #3
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA for searching for a value/highlight/copy

    Sure, sorry about that!

    I attached an example workbook. I am looking to look down the "Country" column for the value USA. If the value USA is there, I want to copy the entire row from that value and paste the whole row into a new sheet.

    Sorry if I was unclear.

    Thanks
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA for searching for a value/highlight/copy

    Try this code and let me know if it works. It should highlight all USA cells in light yellow, and copy the rows (unhighlighted) to sheet 2

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA for searching for a value/highlight/copy

    That works very well, thanks very much. I am going to try to modify the code to use it with my larger data set. I'll let you know if I have any questions.

  6. #6
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA for searching for a value/highlight/copy

    For some reason it copies and pasted the headers (row1) as well onto the new sheet. Do you know which line of your code is causing this ?

  7. #7
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA for searching for a value/highlight/copy

    It was written to include that. Try this modification and report back.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA for searching for a value/highlight/copy

    That works great, I'm just having trouble adjusting it to the data set I was trying to use it for. But that is simply because I am inexperienced with this stuff. Best way to learn though

    Thanks again

  9. #9
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA for searching for a value/highlight/copy

    What troubles are you having with the data range? Perhaps we can help clarify things for you.

  10. #10
    Registered User
    Join Date
    08-11-2011
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA for searching for a value/highlight/copy

    Hm it may be easier if there wasnt an autofilter being used. Do you think it's possible to do this using an if statement?

  11. #11
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: VBA for searching for a value/highlight/copy

    Does this code work better for you?

    Please Login or Register  to view this content.

+ 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