+ Reply to Thread
Results 1 to 2 of 2

MessageBox in If Statement

  1. #1
    Registered User
    Join Date
    06-29-2010
    Location
    Minneapolis, MN
    MS-Off Ver
    Excel 2016
    Posts
    75

    MessageBox in If Statement

    Hi all,

    I have some code (that doesn't work) that is intended to do the following:

    If Cell DP11 <> "OK", then display a messagebox saying: "ERROR" and end the sub.

    Else

    Hide all the columns where the corresponding values in row 4 is = 0. Here is what I have:

    Sub HideRows()

    Dim i, startcol, endcol As Integer

    startcol = 3

    endcol = 32

    If ((Range(DP11).Value <> "OK")) Then

    MsgBox ("ERROR")

    Else

    For i = startcol To endcol

    If ((Cells(4, i).Value = "" Or Cells(4, i).Value = 0)) Then
    Columns(i).EntireColumn.Hidden = True
    Else
    Columns(i).EntireColumn.Hidden = False
    End If
    Next i
    End If
    End Sub

    Can anyone help make the code work? Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: MessageBox in If Statement

    DP11 should be in quotes.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

+ 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