+ Reply to Thread
Results 1 to 5 of 5

VBA Find Function Question

  1. #1
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    VBA Find Function Question

    Hi, I have the following codes, just an example, that I use to find a word "Hello World" in an active worksheet. If it finds "Hello World", it will update cell A1 to "1000". Else, if it doesn't find "Hello World", it updates cell A2 to 2000. However, the codes breaks when it doesn't find "Hello World". How do I modify the code, so that the FIND function returns true or false or something similar, so that I can use the IF function to update the worksheet correctly.

    I want a FIND function to work like this. If the worksheet has a world "Hello World", it updates cells A1 to 1000, and if it doesn't find the word "Hello World", it updates cells A2 to 2000.

    I really appreciate the help. Thank you.

    HTML Code: 

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: VBA Find Function Question

    Please Login or Register  to view this content.


    1. You declared Counter as an integer but you assigned a string to it when you put quotes around "1" making VBA convert it to an integer.
    2. Notice the space: If IsJournal Entry = "Hello World"
    3. Your If is missing a THEN
    If IsJournalEntry = "Hello World" Then
    It should look like:
    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Re: VBA Find Function Question

    Thank you very much!

  4. #4
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Re: VBA Find Function Question

    I just double check the code and it doesn't work. I think it's because of this line of code, IsJournalEntry = ActiveCell.Value, this code will set it back to a blank string. So when the IF function check, it always update cell A2 with 2000 regarless if it find the words "Hello World" or not. The reason I'm doing this is because I want to check if a sheet has a data or it's a support for the data. If it has certain words in the sheet, it's a data sheet, and if it doesn't have certain words, it's a support sheet. Is there a better way to write it? I know mine is not an efficient way to do it.

  5. #5
    Forum Contributor
    Join Date
    05-04-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    184

    Re: VBA Find Function Question

    I found a way to get it to work. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. add in the parameters to the Find function to only find an exact match.
    By jakeembx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-07-2014, 08:57 AM
  2. [SOLVED] Problem with Find function. Need to find Exact match
    By SMILE in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2012, 07:07 AM
  3. find function doesnt find imported info
    By dscott2479 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-12-2011, 07:11 PM
  4. Excel Find and . Find Method Question
    By cldcp00 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2010, 07:34 AM
  5. Using find function to find entries in multiple cells
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2007, 08:45 PM

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