+ Reply to Thread
Results 1 to 2 of 2

If statement to test value in cell before running code

  1. #1
    Forum Contributor
    Join Date
    02-09-2011
    Location
    Perth, Australia
    MS-Off Ver
    2016
    Posts
    161

    If statement to test value in cell before running code

    Hi forum,

    I have some code that is run by pressing a command button after some data is pasted into a worksheet and I want the code to first confirm that the correct data has been pasted into the three columns that my main code uses (the source data is provided by another department and they often change the positions of columns).
    I have been working through an Excel 2010 VBA book to try to work this out for myself but haven’t found an example similar enough to help me.
    The code I need is (very, very roughly) something like this:

    Please Login or Register  to view this content.
    Using the first statement as an example, if A1 contains the text “Actual Date” the code moves to the next If, then, if all OK, my main code runs.
    If the text in cell A1 is anything other than “Actual Date” the message is displayed and the code aborted (giving the operator the opportunity to correct the problem).
    Can someone please correct my very rough code above to code that will run as required?
    Any assistance would be very much appreciated.

    Thanks very much

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: If statement to test value in cell before running code

    Try this:

    Please Login or Register  to view this content.
    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

+ 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