+ Reply to Thread
Results 1 to 6 of 6

If/then with case statement

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2013
    Location
    denver
    MS-Off Ver
    Excel 2003
    Posts
    17

    Cool If/then with case statement

    Attached Excel Sheet.


    If record 2 (B Column minus header) contains zero, put the value "ZZ"; however if the value is greather than zero go to Record 1 (Column A) to determine the value in the case statment and populate the value in Record 3 (Column C)


    Highlighted in yellow are the correct answers.

    Thank you.
    Attached Files Attached Files
    Last edited by nhi; 05-29-2013 at 04:31 PM.

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: If/then with case statement

    formula for C2:
    =IF(B2=0,"ZZ",IF(A2="A","XX",IF(A2="B","UA",IF(A2="C","XX",IF(A2="D","UA","")))))
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    02-01-2013
    Location
    denver
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: If/then with case statement

    Thanks, however I need a VBA formulation.

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: If/then with case statement

    As a loop for the data in the sample:
    Sub Test()
        Dim i As Long
        With ActiveSheet
            For i = 2 To 5
                If .Cells(i, 2).Value = 0 Then
                    .Cells(i, 3).Value = "ZZ"
                Else
                    Select Case .Cells(i, 1).Value
                        Case "A", "C"
                            .Cells(i, 3).Value = "XX"
                        Case "B", "D"
                            .Cells(i, 3).Value = "UA"
                        Case Else
                            .Cells(i, 3).Value = "--"
                    End Select
                End If
            Next i
        End With
    End Sub

  5. #5
    Registered User
    Join Date
    02-01-2013
    Location
    denver
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: If/then with case statement

    Is there anyone to make the program dynamic with ranges, whereas lets say the range of Record 1 (Column A) is changing. ( For i = 2 to n?)

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: If/then with case statement

    For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
    till last row of data in column A

+ 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