active cell triggering events... only after it's no longer active ?

CatyH

Board Regular
Joined
Jun 27, 2017
Messages
84
Office Version
  1. 365
I started with hardcoding this task which worked really well. But then, trying to put parameters in here instead has really thrown me off.
The scenario: I have three columns: C (percent), D (hours), E (dollars)

range-object.html


When the user enters a value into column C for a particular row, I want that action to trigger calculating values to put in columns D and E for that row.
When the user enters a value into column D for a particular row, I want that action to trigger calculating values to put in columns C and E for that row.
When the user enters a value into column E for a particular row, I want that action to trigger calculating values to put in columns C and D for that row.

The problem SEEMS to be that when I run this code below, the events are not triggered until I get out of the current cell - which means that "THIS" cell changes to my new cell and the code being run is based off the NEW this cell instead of the one I wanted...

Also - this may or may not be related... it took me about 2 hours to figure out how to build a "range" based on the current cell. I wanted to build the (type range):
PercentCell to be the percent column and THIS row (where THIS is the active cell)
HoursCell to be the hours column and THIS row (where THIS is the active cell)
DollarsCell to be the dollars column and THIS row (where THIS is the active cell).
I suspect this may be one thing wrong with my code and possibly a place to start for why it's not working well...


Wish I could somehow deliver on a plate of homemade chocolate chip cookies to whomever can help me solve this conundrum! Alas, I can only offer my undying gratitude... Thank you in advance for your help!

cat


Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Application.EnableEvents = True
    
    
Dim thisCell As Range
Dim thisCol As Integer
Dim thisRow As Integer


Dim percentCellRef As String
Dim percentCell As Range
Dim percentCol As Integer


Dim hoursCellRef As String
Dim hoursCell As Range
Dim hoursCol As Integer


Dim dollarsCellRef As String
Dim dollarsCell As Range
Dim dollarsCol As Integer


Set thisCell = ActiveCell
thisCol = ActiveCell.Column
thisRow = ActiveCell.Row




percentCellRef = "C" & thisRow
Set percentCell = Range(percentCellRef)
percentCol = 3


hoursCellRef = "D" & thisRow
Set hoursCell = Range(hoursCellRef)
hoursCol = 4


dollarsCellRef = "E" & thisRow
Set dollarsCell = Range(dollarsCellRef)
dollarsCol = 5




            
            




  If thisCol = percentCol Then
    CalcHoursFromPct hoursCell
    CalcDollarsFromPct dollarsCell
      
   Else
      
      If thisCol = hoursCol Then
        CalcPctFromHours percentCell
        CalcDollarsFromHours dollarsCell
      
      Else
      
        If thisCol = dollarsCol Then
          CalcPctFromDollars percentCell
          CalcHoursFromDollars hoursCell
       
        Else
          MsgBox ("Else")
      
        End If
      End If
  End If




End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The Target argument is the cell that was changed, so you should use that instead of Activecell.
 
Upvote 0
ah - thanks... just tried changing all my ActiveCell to TargetCell and it's still buggy... :/ Run Time error 424 Object required... ?
 
Upvote 0
Not TargetCell, just Target - as in:

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

:)
 
Upvote 0
OHHHHHHHHHHHHHH! you mean IN the code put Target, not TargetCell...

GOT IT!!

AND IT WORKS!!!! :) YOU ARE AMAZING!!!!

THANK YOU THANK YOU THANK YOU!!!!!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top