+ Reply to Thread
Results 1 to 3 of 3

Make Column Mandatory if another cell in same row has data in it.

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Make Column Mandatory if another cell in same row has data in it.

    I am trying to write some VBA to make a column mandatory only if there is data in a different column.

    Here's my problem:

    In worksheet "For Sales", If column B contains data, then make column AW a mandatory field for the associated row.

    I have tried multiple different combinations of logic/code and I can't get this to work. I would like to assign this macro to a button if possible.

    Any help/advise is greatly appreciated.

    Thanks,

    Matt

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,874

    Re: Make Column Mandatory if another cell in same row has data in it.

    Hi Matt. Try:
    Sub Test()
        Application.ScreenUpdating = False
        Dim LastRow As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Dim InputVal As String
        Dim rng As Range
        For Each rng In Range("B2:B" & LastRow)
            If rng <> "" And Range("AW" & rng.Row) = "" Then
                Do
                    InputVal = InputBox("Please type an entry for cell : " & "AW" & rng.Row & ".")
                    If InputVal <> "" Then
                        Range("AW" & rng.Row) = InputVal
                        Exit Do
                    ElseIf InputVal = "" Then
                        MsgBox "You must type an entry for cell: " & "AW" & rng.Row & ".", vbOKOnly, ""
                    Else: Exit Do
                    End If
                Loop
            End If
        Next rng
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Make Column Mandatory if another cell in same row has data in it.

    Sub RunMe()
    Dim ws As Worksheet:    Set ws = Sheets("For Sales")
    Dim iBox As String
    Dim c As Range
    
    For Each c In ws.Range("B1:B" & ws.Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeConstants)
        If ws.Range("AW" & c.Row).Value = "" Then
    reEnter:
            iBox = InputBox("Enter a value for cell AW" & c.Row)
            If iBox = "" Then
                MsgBox ("You must enter a value for the cell")
                GoTo reEnter
            Else
                ws.Range("AW" & c.Row).Value = iBox
            End If
        End If
    Next c
            
    End Sub

+ 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. Replies: 5
    Last Post: 03-20-2013, 12:30 PM
  2. Replies: 14
    Last Post: 01-22-2013, 12:07 PM
  3. How to make data in cells mandatory?
    By r.kondapalli in forum Excel General
    Replies: 8
    Last Post: 01-18-2011, 11:30 AM
  4. [SOLVED] How can I make a cell mandatory?
    By [email protected] in forum Excel General
    Replies: 3
    Last Post: 02-06-2006, 07:10 PM

Tags for this Thread

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