How to extract value from cell with formula other than using the direct change in cell

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
How do I make this code respond to cells with formulasome instead of the Target?

I am running into some troubles and wish there is a way to use cells with formulas instead of direct changing from the cells.
Thanks


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim fPath As String, sFile$
If Target = Me.[h9] Then
    fPath = ThisWorkbook.Path & "" & Me.CmbTerm.Text
    sFile = Dir(fPath & "" & Right(Me.[h9].Text, 3) & ".*")
    If sFile <> vbNullString Then
      Me.Image1.Picture = LoadPicture(fPath & "" & sFile)
    Else
        Me.Image1.Picture = LoadPicture("")
    End If
    If Err.Number = 53 Then Me.Image1.Picture = LoadPicture("")
End If
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi,
To work with Cell Changes with Formula's you will nee to use Calculate event. Unfortunately, this event dose not have the range parameter Target so you will need to employ a little bit of trickery by using a cell or it's ID property as a place holder for your formula to compare changes f value against.

Untested but made some changes to your code - see if it does what you want


Code:
Private Sub Worksheet_Calculate()
Dim fPath As String, sFile$
On Error GoTo exitsub
With Me.[h9]
    If .Value <> .ID Then
    Application.EnableEvents = False
    fPath = ThisWorkbook.Path & "" & Me.CmbTerm.Text
    sFile = Dir(fPath & "" & Right(Me.[h9].Text, 3) & ".*")
    If sFile <> vbNullString Then
      Me.Image1.Picture = LoadPicture(fPath & "" & sFile)
    Else
        Me.Image1.Picture = LoadPicture("")
    End If
    .ID = .Value
End If
End With


exitsub:
If Err.Number = 53 Then Me.Image1.Picture = LoadPicture("")
Application.EnableEvents = True
End Sub

may need some adjustment but hopefully give some idea.

Dave
 
Upvote 0
Hello Dave,
The code worked just like magic!!!

Thanks a lot again
Kelly
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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