+ Reply to Thread
Results 1 to 14 of 14

VBA Macro for search specific word and input specific value

  1. #1
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    VBA Macro for search specific word and input specific value

    I am newbie in Excel Macro. I am trying to do a very simple macro for excel. The Macro will works like IF a specific cell (for example D) contains some categorized string then it will return a specific value in another cell. For an example if any cell of column D contains 'Books', 'Food', 'Fruits' string anywhere of its cell then it will return 01, 02, 03 respectively in Column E. For sure it will very easy task and probably this kind of question asked earlier but as I am newbie please let me know in a brief or any link to get the solution.

    I am trying to use this code I found.

    Please Login or Register  to view this content.
    But It returns an error: Else without IF. What should I do?

    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: VBA Macro for search specific word and input specific value

    Hi,

    the macro should run if you put a line break in the first "If" line. (Explanation: if the whole "If...Then" session is in one line, you don't need "End if".)
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: VBA Macro for search specific word and input specific value

    Hi

    Try this:

    Please Login or Register  to view this content.
    The code for this is:

    Please Login or Register  to view this content.
    I have a button and the above code is for that button.
    Attached Files Attached Files
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Macro for search specific word and input specific value

    Many solutions possible

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  5. #5
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Macro for search specific word and input specific value

    Thank you. But there is a problem also. Actually I want to find Books, Fruits or foods from a group of string of Cell and return 01, 02, 03. In my Selected cell It contains "Amin Books", "BV Foods", "Fresh Fruits". So I think the code need some changes. I also want to ignore case sensitivity.

  6. #6
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: VBA Macro for search specific word and input specific value

    Now try this code:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Macro for search specific word and input specific value

    Just Last one thing. If I want to input string instead of number what should I do (Such as 01 instead of 1). I tried
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.

  8. #8
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Macro for search specific word and input specific value

    @jraj1106, I do not want to hijack your solution but Toton also requested case insensitive matching so I suggest to add using UCASE to both the contents of the cell and the search string

  9. #9
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: VBA Macro for search specific word and input specific value

    Okay. You can do it.

  10. #10
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Macro for search specific word and input specific value

    @jraj1106....So what will be the final code boss? I need string in output and case insensitivity.

  11. #11
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: VBA Macro for search specific word and input specific value

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Macro for search specific word and input specific value

    Its solved the case problem but still its giving 1, 2 and 3 instead of 01, 02 and 03 respectively.

  13. #13
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: VBA Macro for search specific word and input specific value

    Change the format of col E to text format. Then run the macro.

  14. #14
    Registered User
    Join Date
    04-30-2012
    Location
    Dhaka
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: VBA Macro for search specific word and input specific value

    Quote Originally Posted by jraj1106 View Post
    Change the format of col E to text format. Then run the macro.
    Thanks a lot...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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