+ Reply to Thread
Results 1 to 14 of 14

Add wildcard to workbook cell searching macro. (ws.cells)

  1. #1
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32

    Add wildcard to workbook cell searching macro. (ws.cells)

    This is an enhancement on a previous solution i needed help with.

    http://www.excelforum.com/excel-prog...problem-2.html

    I have a workbook with a macro that searches through worksheets to find certain values and place the location of the value in a worksheet cell. The following line ontains the found cell.

    Please Login or Register  to view this content.
    This on the first run contains:

    01_Access/aa7 (House Num)

    Which has been fine as this is the specified search criteria. The search criteria is the exact same now but i now need to compensate with values that have characters before and after e.g.

    AAA [01_Access/aa7 (House Num), 4]

    This needs to be done without altering the search criteria. Ive tried putting the wildcard character into the above line and its not working, maybe im using it wrongly im not sure.

    Can anyone enlighten me?
    Last edited by chris-uk-lad; 01-06-2009 at 08:10 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260
    If your search criteria is '01_Access/aa7 (House Num)' then the code you have will already find cells that contain that value since you are using xlPart, not xlWhole as the LookAt argument.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437
    You are already using the xlpart option on the find so wildcards should not be needed.

    But I guess you could add wildcards

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32
    thanks for the quick response. Ive taken the example Phil derived last time and altered to show what i mean. (attatched)

    Sheet 1 (Maps) should populate Mapped/Referenced when the value in Mapping Reference is found. This works when the cell on Sheet 4 (S2) contains:

    Please Login or Register  to view this content.
    However when altered to contain:

    Please Login or Register  to view this content.
    [/CODE]

    It does not find the cell.

  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,260
    The problem is not with the Find (which locates the data just fine) but with your Like comparison, which needs to be adjusted to:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32
    that worked fine, thank you

    just a final quesiton, related to the worksheet not the task,

    how would i specify as an output, a certain cell within say, Sheet3, e.g A:2?

    So like:

    Please Login or Register  to view this content.
    (i know the above doesnt work, just an idea of what id like to do)

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437
    either of these

    Please Login or Register  to view this content.

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260
    Please Login or Register  to view this content.
    with either of Andy's suggested syntaxes.

  9. #9
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437
    thanks. I missed that missing dot.

  10. #10
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32
    sorry i didnt specify better, ws.cell seems to only call the first sheet (Sheet1), i actually want Sheet3 specified.

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437
    I assumed ws was an object you had declared that referenced the appropriate sheet.

    If not then

    Please Login or Register  to view this content.
    Or what ever the code name of the sheet is.

  12. #12
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32
    Thats worked fine, thanks everyone for your help.

  13. #13
    Registered User
    Join Date
    09-28-2008
    Location
    Leeds
    Posts
    32
    Apologies, premmature solving.

    That works fine, when the sheet isnt named XD

    So instead of using Sheet3 / Sheet4 etc. how can i use it based on the sheets name instead of corresponding number? e.g worksheet "Housing"

    Debug.Print Housing.Range("D3").Value

    this doesnt work, requires an object :x

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260
    You would use:
    Please Login or Register  to view this content.
    Andy's code was using codenames - usually more reliable as they do not change when you alter the tab name.

+ 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