+ Reply to Thread
Results 1 to 9 of 9

VBA Error with If, Or, Then

  1. #1
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    VBA Error with If, Or, Then

    I am using the below code and getting an error when I add in the "or" statement to the If cells <> Weight or Letter then multiply the cells by 1.


    Where am I going wrong on this??


    Please Login or Register  to view this content.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: VBA Error with If, Or, Then

    Try

    Cell.Text <> "Letter"
    or
    Cell.Value <> "Letter"

    I really think your logic is wrong. Try improving your logic with a "AND" type conjunction.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Error with If, Or, Then

    Marvin, how would you rewrite this with an And?

  4. #4
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Error with If, Or, Then

    I tried both value and text and still getting a runtime error.

    It highlights the Cell.value = cell.value *1 part for the error.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,417

    Re: VBA Error with If, Or, Then

    Please Login or Register  to view this content.
    will always be True.

    If cell = "Letter" then cell <> "Weight" and if cell = "Weight" then cell <> "Letter".

    That means you will try to increment the cell value even when there is a text value present.

    Change it to
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: VBA Error with If, Or, Then

    Thank you for your help. This did work perfectly.

    I am very new to using VBA, and programming it.... I am used to thinking in terms of writing formulas in excel... not in VBA.... I would have used an if/or /then there.... I understand why it would not have worked here though.

    Thanks again for your help.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,417

    Re: VBA Error with If, Or, Then

    You're welcome. Thanks for the rep.

    If you were ORing the conditions in a formula, it wouldn't work there either.

  8. #8
    Registered User
    Join Date
    07-19-2016
    Location
    Ahmedabad, India
    MS-Off Ver
    2013
    Posts
    3

    Re: VBA Error with If, Or, Then

    Removed post
    Last edited by alkesh4u; 07-19-2016 at 09:21 AM. Reason: Not relavant, posted in wrong location

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,417

    Re: VBA Error with If, Or, Then

    @alkesh4u: Welcome to the forum.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.


    AND, when you create your own thread, please remember to use Code Tags ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

+ 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. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  2. [SOLVED] Run-tim error -2147467259(80004005): Automation error Unspecidied error
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2014, 12:12 PM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. Receiving following error “Complie error : syntax error” Help
    By masond3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2012, 10:19 AM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  6. Error 75 File/Path access error, sometimes Error 1004
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-16-2011, 02:35 PM
  7. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 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