+ Reply to Thread
Results 1 to 3 of 3

Code for Multiple If conditions

Hybrid View

Raushan Code for Multiple If... 10-10-2007, 03:21 AM
nyeoman Hi Raushan, I'm not... 10-15-2007, 02:39 AM
Raushan Hi Nyeoman, Sorry for late... 10-25-2007, 08:23 AM
  1. #1
    Registered User
    Join Date
    04-24-2007
    Posts
    20

    Code for Multiple If conditions

    Hi Friends,

    Is it possible with the vba code or formula,

    For example, condition 1,
    When cell E=blank AND A= 2 or 3 or 4 or 5, look at B. If B is a 2007 date, THEN add no. of conditions satisfied for Lvl2 or Lvl3 or Lvl4 or Lvl5 to ( table current year Total Current DU Operating at CMMI Lvl 2 or 3 or 4 or 5) =table year end,CMMI Lvl 2 or 3 or 4 or 5 DU Year End Forecast .

    Condition2,
    When cell E = 2 AND A = 3 or 4 or 5, look at B. If B is a 2007 date, THEN Subtract the no. of conditions satisfied for Lvl2 from (table current year,Total current DU Operating at CMMI Lvl 2) =CMMI Lvl 2 2007 DU Year End Forecast
    AND Add no. of conditions satisfied for Lvl3 or 4 or 5 to (table current year, Total current DU Operating at CMMI Lvl 3 or 4 or 5) =table year end,CMMI Lvl 3 or 4 or 5 DU Year End Forecast.

    condition 3,
    When cell U = 3 AND Z = 4 or 5, look at AA. If AA is a 2007 date, THEN Subtract 1 from (table current year, Total DU Operating at CMMI Lvl 3) =table year end,CMMI Lvl 3 2007 DU Year End Forecast, AND

    Add 1 to (table current year,Total DU Operating at CMMI Lvl 4 or 5) =table year end,CMMI Lvl 4 or 5 DU Year End Forecast.

    also condition 4,
    When U = 4 AND Z = 5, look at AA. If AA is a 2007 date, THEN Subtract 1 from (current year,Total DU Operating at CMMI Lvl 4) =table year end,CMMI Lvl 4 2007 DU Year End Forecast, AND

    Add 1 to (table current year,Total DU Operating at CMMI Lvl 5) =table year end,CMMI Lvl 5 DU Year End Forecast.

    Please help,how to start with Macro code for this?
    Please find the attachment below for reference,

    thanks
    Raushan
    Attached Files Attached Files
    Last edited by VBA Noob; 10-10-2007 at 03:25 AM.

  2. #2
    Registered User
    Join Date
    10-15-2007
    Posts
    7
    Hi Raushan,
    I'm not completely positive I understand the logic of your worksheet - so pardon some of the vagueness in my answer. However, I believe that this will get you started in the right direction.

    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Value = "" And (Sheet1.Cells(Target.Row, 1) = "2" Or Sheet1.Cells _
    (Target.Row, 1) = "3" Or Sheet1.Cells(Target.Row, 1) = "4") Then
        Dim DateInCell As Date
        Dim YearInCell As Integer
        DateInCell = Sheet1.Cells(Target.Row, 2)
        YearInCell = Year(DateInCell) 'Grab just the year from the date.
          If YearInCell = CInt(2007) Then
            Dim valueInLevel2 As Integer
            valueInLevel2 = CInt(Sheet1.Cells(11, 8)) + CInt(Sheet1.Cells(12, 8)) _ 
                            + CInt(Sheet1.Cells(13, 8)) + CInt(Sheet1.Cells(14, 8)) 'Add all lvl2 values
            'Display Values with code
          End If
    End If
    
    End Sub
    This should get through your 'condition 1' - assuming I'm understanding your explanation of the condition correctly. You can reapply the logic of nesting the if..then.else statements to determine your other criteria.

  3. #3
    Registered User
    Join Date
    04-24-2007
    Posts
    20

    Exclamation

    Hi Nyeoman,

    Sorry for late responce, actually I was out of station.

    Thanks for your responce,
    Actually I'm not getting anything after putting ur code into the VB Editer of my spreadsheet.
    what I understand from ur code is, you adding all the stisfied conditions into level 2, But
    condition here is
    When cell E=blank AND A= 2 or 3 or 4 or 5, look at B. If B is a 2007 date, THEN add no. of conditions satisfied for Lvl2or Lvl3 or Lvl4 or Lvl5 to ( table current year Total Current DU Operating at CMMI Lvl 2 or 3 or 4 or 5) =table year end,CMMI Lvl 2 or 3 or 4 or 5 DU Year End Forecast .
    this is what I need here,

    When cell E=blank AND A= 2 , look at B. If B is a 2007 date, THEN add no. of conditions satisfied for Lvl2 to (table current year Total Current DU Operating at CMMI Lvl 2 )
    So in cell K19=K11+ stisfied conditions for level2.
    Likewise
    When cell E=blank AND A= 3 , look at B. If B is a 2007 date, THEN add no. of conditions satisfied for Lvl3 to (table current year Total Current DU Operating at CMMI Lvl 3 )
    So in cell K20=K12+ stisfied conditions for level3..........
    K21=K13+ stisfied conditions for level4
    K22=K14+ stisfied conditions for level5.
    also could you please paste ur code into the spreadsheet
    thanks
    Raushan

+ 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