Data Validation - Worksheet change VBA

bravia

New Member
Joined
Apr 2, 2020
Messages
6
Office Version
  1. 365
Platform
  1. MacOS
Hi there,

I'm very new to the VBA, and have a reasonable Excel knowledge of formulas etc.

I have a sheet that I use an Array Formula to give me 4 options which is referenced in a range by a data validation drop down list (each row has it's own range & result.).

The Vlookup is based on the value in col D, (searches on sheet 'Fixture Library' and result is produced in cols N-Q, there will only be a maximum of 4 results. The data validation references the N-Q range for each row. This all works well.

The next step is what I'm struggling with - I have found a great VBA script online that on clicking on the data validation cell will refresh the result to the first. I would like instead of clicking on the cell with the validation that anytime there is a change in col D, it refreshes it's result in col F. Is this possible can anyone help with the script?

Example file is here: Dan Young sent you 1 item. - A number of cols are hidden/deleted to prevent confusion.

Script I am currently using:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice 20160725
    Dim xFormula As String
    On Error GoTo Out:
    xFormula = Target.Cells(1).Validation.Formula1
    If Left(xFormula, 1) = "=" Then
        Target.Cells(1) = Range(Mid(xFormula, 1)).Cells(1).Value
    End If
Out:
End Sub

••••ˇˇˇˇ
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xFormula As String
    
    ' if unit # changes
    If Target.Column = 1 Then
        xFormula = Range("F" & Target.Row).Validation.Formula1
        Range("F" & Target.Row).Value = Range(Mid(xFormula, 1)).Cells(1)
    End If
    
End Sub
 
Upvote 0
Thanks! That works perfectly! Since this is working it's brought up another little tweak I could do with some help with.... If a cell in col A is empty it doesn't update col F with an empty value, is it possible to include that in the script?
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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