Results 1 to 3 of 3

Trouble with if else then macro

Threaded View

  1. #1
    Registered User
    Join Date
    04-08-2015
    Location
    Auckland
    MS-Off Ver
    2013
    Posts
    1

    Trouble with if else then macro

    Hi all,

    I am trying to code a macro that first checks cells B4,C4,D4 and E4 to check they have been filled in. If they haven't a msgbox should pop up prompting to fill in required cells. If the cells are filled in the various functions in the recorded macro should run.

    Note, All relevant columns have data validation applied.

    I have tried several methods. IsNull() with OR for the various cells, B4=""..., B4=0.. etc. but I can't seem to get it to work correctly.

    In the code below, if the cells are empty the msgbox comes up however even when the cells are completed the msgbox comes up and the macro does not run the Else portion of the code.
    If B4 = "" Then
       MsgBox ("Please enter data in all cells")
       ElseIf C4 = "" Then
       MsgBox ("Please enter data in all cells")
        ElseIf D4 = "" Then
       MsgBox ("Please enter data in all cells")
       ElseIf E4 = "" Then
       MsgBox ("Please enter data in all cells")
       Else
        ActiveSheet.Unprotect
        Rows("4:4").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("B5:E5").Select
        Range("E5").Activate
        ActiveSheet.Shapes.Range(Array("Rectangle 7")).Select
        Range("B5:E5").Select
        Range("E5").Activate
        Selection.Locked = True
        Selection.FormulaHidden = False
        Range("B2:E4").Select
        Range("E4").Activate
        Selection.Locked = False
        Selection.FormulaHidden = False
        ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
            False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
            AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
            :=True, AllowInsertingHyperlinks:=True, AllowDeletingColumns:=True, _
            AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
    End If
    End Sub
    Last edited by Leith Ross; 04-08-2015 at 10:13 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. macro for turning columns into rows
    By Shanehickey2497 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2013, 01:08 AM
  2. Macro Trouble
    By tonychopra194 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-30-2012, 02:57 AM
  3. Trouble with If-Then-Else in a VBA Macro
    By garden_gnome in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-07-2012, 04:17 PM
  4. Replies: 0
    Last Post: 08-26-2010, 11:49 AM
  5. MACRO TROUBLE
    By HELP in forum Excel General
    Replies: 2
    Last Post: 06-07-2006, 11:15 AM

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