Consulting

Results 1 to 6 of 6

Thread: Solved: If Value in one column is something and another column is mandatory

  1. #1

    Solved: If Value in one column is something and another column is mandatory

    Hi

    Please see the attached file in this

    If value in Budget Type = 'Oracle paying to partner or
    'Partner paying to supplier or
    'Partner paying to Oracle

    then

    OPN Partner Country
    OPN Partner Name
    Partner Type columns are mandatory

    Can any one help me by providing vba code to perform above action

    Regards,
    Rajesh

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Add a formula of =AA2 in IV2, and copy down as far as you need, then use

    [vba]



    Private Sub Worksheet_Calculate()
    Const WS_RANGE As String = "IV" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    With ActiveCell

    If .Row > 1 Then

    If Me.Cells(.Row, WS_RANGE).Value = "Oracle paying to partner" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to supplier" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to Oracle" Then

    If .Cells(.Row, "S").Value = "" Or _
    .Cells(.Row, "W").Value = "" Or _
    .Cells(.Row, "X").Value = "" Then

    MsgBox "Partner name,company and type are mandatory"
    .Value = ""
    End If
    End If
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    This is worksheet event code, which means that it needs to be
    placed in the appropriate worksheet code module, not a standard
    code module. To do this, right-click on the sheet tab, select
    the View Code option from the menu, and paste the code in.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    A sledgehammer version, using a Userform
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Private Sub Worksheet_Calculate()
    Const WS_RANGE As String = "IV" '<== change to suit

    On Error Goto ws_exit
    Application.EnableEvents = False

    With ActiveCell

    If .Row > 1 Then

    If Me.Cells(.Row, WS_RANGE).Value = "Oracle paying to partner" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to supplier" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to Oracle" Then

    If .Cells(.Row, "S").Value = "" Or _
    .Cells(.Row, "W").Value = "" Or _
    .Cells(.Row, "X").Value = "" Then

    MsgBox "Partner name,company and type are mandatory"
    .Value = ""
    End If
    End If
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub


    HI,

    This code is working fine for me but i have filled some values in column S W and X still its showing the error message could you please help me on this one
    Last edited by rajesh nag; 03-22-2008 at 02:10 AM.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sorry about that, try this revision

    [vba]

    Private Sub Worksheet_Calculate()
    Const WS_RANGE As String = "IV" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    With ActiveCell

    If .Row > 1 Then

    If Me.Cells(.Row, WS_RANGE).Value = "Oracle paying to partner" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to supplier" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to Oracle" Then

    If Me.Cells(.Row, "S").Value = "" Or _
    Me.Cells(.Row, "W").Value = "" Or _
    Me.Cells(.Row, "X").Value = "" Then

    MsgBox "Partner name,company and type are mandatory"
    .Value = ""
    End If
    End If
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Quote Originally Posted by xld
    Sorry about that, try this revision

    [vba]

    Private Sub Worksheet_Calculate()
    Const WS_RANGE As String = "IV" '<== change to suit

    On Error GoTo ws_exit
    Application.EnableEvents = False

    With ActiveCell

    If .Row > 1 Then

    If Me.Cells(.Row, WS_RANGE).Value = "Oracle paying to partner" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to supplier" Or _
    Me.Cells(.Row, WS_RANGE).Value = "Partner paying to Oracle" Then

    If Me.Cells(.Row, "S").Value = "" Or _
    Me.Cells(.Row, "W").Value = "" Or _
    Me.Cells(.Row, "X").Value = "" Then

    MsgBox "Partner name,company and type are mandatory"
    .Value = ""
    End If
    End If
    End If
    End With

    ws_exit:
    Application.EnableEvents = True
    End Sub
    [/vba]

    Thanks A Lot

    Regards,
    Rajesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •