+ Reply to Thread
Results 1 to 8 of 8

Column Search for Data

  1. #1
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151

    Column Search for Data

    Good day,

    How would this be accomplished using VBA:

    Search a column for data

    If data is found, copy the data to another cell.
    ---------

    Currently I am just copying a column range and pasting it using VBA. But this copies and pastes the specified range whether data is present or not. Any Ideas?

    Your time is sincerely appreciated.

  2. #2
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    NewExcelUser,

    Here is how I handle a search for a specific piece of data. This is very generic and would need to be adapted to your worksheet.

    Please Login or Register  to view this content.
    Hope this helps!
    Last edited by boylejob; 06-11-2007 at 07:50 PM.
    Sincerely,
    Jeff

  3. #3
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151
    Thanks for replying boylejob,

    Can this code be modified so it is able to search not just for specific data, but any data in a specific column?

    Incidentally, I just tried the code above using "Widget" as a search item. It does nothing if the item is found but says "not found" in the first available cell if it is not found. It is supposed to copy the found information over no?

    Basically what I want to do is:

    If any cell in column A <> " " Then copy the cells that <> " " to a different worksheet.

    Sincere Thanks.
    Last edited by NewExcelUser; 06-11-2007 at 10:08 PM.

  4. #4
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    NewExcelUser,

    Not knowing exactly what you were wanting to do, I just copied some code out of one of my programss to give you something to work with. I did not test it, but now that I look at it what it would do is find "Widget" on Sheet1 and then copy into Cell A1 of Sheet2 whatever was found in Column B of the Row on which "Widget" was found. Hope that makes sense.

    Yes, the code can search for a variable which is basically what it is already doing. I just had it hard coded to give you a place to start. I am attaching an example spreadsheet which might make it a little bit clearer how the code works.

    Hope this helps you get started!
    Attached Files Attached Files

  5. #5
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    NewExcelUser,

    I'm sorry I missed the last part of your question. This code should do what you are asking.
    Please Login or Register  to view this content.
    This will look in Column A of Sheet1 and if the cell is not blank, it will copy the value to Column A of Sheet2.

    I apologize for missing the last part of your last post and I hope is what you are looking form.

  6. #6
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151
    Hi Boylejob,

    I appreciate the time you have taken to explain everything step by step in the example you attached, and the follow up code that you posted. It works flawlessly.

    One question:
    If I wanted to modify the code to start copying on row 2 and start pasting in row 2, how would the code be modified?

    Thank you so much!
    Last edited by NewExcelUser; 06-12-2007 at 12:25 AM.

  7. #7
    Forum Contributor
    Join Date
    10-04-2006
    Posts
    151
    Nevermind! Got it! Thank you for all your help

  8. #8
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    NewExcelUser,

    Just in case!

    In the code Cells(lrow, 1) the first item within the parentheses refers to the row number and the second item is the numeric representation of the column.

    To switch this code so that it will look at Column Y

    Please Login or Register  to view this content.
    simply change the 1 to 25
    Please Login or Register  to view this content.
    I'm sure this is what you have already done, but I always like to follow-up.

    I'm glad the code work and it was certainly my pleasure to be of assistance.

+ 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