+ Reply to Thread
Results 1 to 2 of 2

Why am I not getting values in during IF second condition

Hybrid View

  1. #1
    Registered User
    Join Date
    06-10-2023
    Location
    Mumbai India
    MS-Off Ver
    2019
    Posts
    21

    Why am I not getting values in during IF second condition

    Why am I not getting calculated values in Cell A3 as I am getting in Cell M3.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Intersect(Target, Range("J4:J29")) Is Nothing Then
            Dim H As Double
            Dim G As Double
            Dim M As Double
            Dim revPrice As Double
            
            H = Range("H" & Target.Row).Value
            G = Range("G" & Target.Row).Value
            M = Range("M" & Target.Row).Value
            
            If H < 90 And H > 80 Then
                revPrice = G - (H * M * 0.04)
            ElseIf H < 81 And H > 65 Then
                revPrice = G - (H * M * 0.06)
            ElseIf H < 65 And H > 50 Then
                revPrice = G - (H * M * 0.08)
            ElseIf H < 50 And H > 35 Then
                revPrice = G - (H * M * 0.1)
            ElseIf H < 35 And H > 20 Then
                revPrice = G - (H * M * 0.12)
            ElseIf H < 20 And H > 10 Then
                revPrice = G - (H * M * 0.15)
            End If
            
            Range("M3").Value = revPrice
            
        ElseIf Not Intersect(Target, Range("D4:D29")) Is Nothing Then
            Dim revPrice2 As Double
            Dim F As Double
            Dim G2 As Double
            Dim A As Double
            
            F = Me.Range("F" & Target.Row).Value
            G2 = Me.Range("G" & Target.Row).Value
            A = Me.Range("A" & Target.Row).Value
            
            If F < 90 And F > 80 Then
                revPrice2 = G + (F * A * 0.04)
            ElseIf F < 80 And F > 65 Then
                revPrice2 = G + (F * A * 0.06)
            ElseIf F < 65 And F > 50 Then
                revPrice2 = G + (F * A * 0.08)
            ElseIf F < 50 And F > 35 Then
                revPrice2 = G + (F * A * 0.1)
            ElseIf F < 35 And F > 20 Then
                revPrice2 = G + (F * A * 0.12)
            ElseIf F < 20 And F > 10 Then
                revPrice2 = G + (F * A * 0.15)
            End If
            
            Me.Range("A3").Value = revPrice2 ' Place the calculated revPrice2 in cell A3
        End If
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Why am I not getting values in during IF second condition

    May be this. D4:d29 formula is there. Change n value from formula does not trigger Worksheet selectionchange event.
    The given code is not there in NIFTY sheet code. Only first half is there.
    Last edited by kvsrinivasamurthy; 06-17-2023 at 12:37 AM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

+ 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. Count number of values, until the sum of underlying values meets condition
    By dogfights in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-26-2021, 05:16 PM
  2. Replies: 3
    Last Post: 08-07-2018, 10:14 AM
  3. If condition between values
    By bkcffee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-16-2016, 01:53 PM
  4. [SOLVED] sum values with condition
    By Berna11 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-11-2015, 02:00 PM
  5. condition formatting for list of values from key values of appropriate match
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2013, 10:13 PM
  6. Store cell values in an array and return values on specific condition
    By gmalpani in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 11-27-2011, 06:43 AM
  7. if condition to look for values in a row
    By gagan2sandhu in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 07-09-2009, 07:13 AM

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