+ Reply to Thread
Results 1 to 2 of 2

How to modify Worksheet_Change Macro VBA code from Range to Cell

  1. #1
    Registered User
    Join Date
    01-21-2013
    Location
    Gainesville, FL
    MS-Off Ver
    Excel 2007
    Posts
    5

    How to modify Worksheet_Change Macro VBA code from Range to Cell

    The below VBA code works well for Row1 data. Unfortunately, I have more than one row of data that will need the same change function. How could I modify the code to work for Row2, Row3 thru Row99? Note each row would have different conversion factors (Ex. for Row2 instead of 86.67, 28 it would be 184.17, 14)

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rAction As Range
    Set rAction = Range("B1:D1")
    If Intersect(rAction, Target) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    Application.EnableEvents = False
    ady = Target.Address(rowabsolute:=False, columnabsolute:=False)
    If ady = "B1" Then
    [C1] = [B1] / 86.67
    [D1] = [C1] / 28
    End If
    If ady = "C1" Then
    [B1] = [C1] * 86.67
    [D1] = [C1] / 28
    End If
    If ady = "D1" Then
    [C1] = [D1] * 28
    [B1] = [C1] * 86.67
    End If
    Application.EnableEvents = True
    End Sub

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    917

    Re: How to modify Worksheet_Change Macro VBA code from Range to Cell

    If you indicate your conversion factors for each row in two different column, say, F and G, you could try something like this:
    Please Login or Register  to view this content.

+ 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