Dear Excel Guru’s
I’m struggling with one of my last tryouts in Excel Macros.
I would like to have in my sheet combination of Data validation list & Vlookup. But I want to have it in Macro, so user won’t be able to see formulas, delete, edit etc..
I succeed with stand-alone Macro (what was easy), but my intention is have real-time as with formulas. I’ve used Private Sub Worksheet_Change(ByVal Target As Range).
I keep receiving errors “Object doesn’t support this property or method”. I guess the reason might be multi-trigger 1) Private Sub Worksheet_Change 2) rest of code…
Please check the attachment to make clear what am I trying for.
There is working macro: Sub MacroVlookup()
and then Private Sub Worksheet_Change(ByVal Target As Range) in Sheet1 which is not working.
https://drive.google.com/file/d/0B0s-0_lS3QrnMHZPZnlHd3lDRzg/view?usp=sharing
Thanks for your help.
I’m struggling with one of my last tryouts in Excel Macros.
I would like to have in my sheet combination of Data validation list & Vlookup. But I want to have it in Macro, so user won’t be able to see formulas, delete, edit etc..
I succeed with stand-alone Macro (what was easy), but my intention is have real-time as with formulas. I’ve used Private Sub Worksheet_Change(ByVal Target As Range).
I keep receiving errors “Object doesn’t support this property or method”. I guess the reason might be multi-trigger 1) Private Sub Worksheet_Change 2) rest of code…
Please check the attachment to make clear what am I trying for.
There is working macro: Sub MacroVlookup()
and then Private Sub Worksheet_Change(ByVal Target As Range) in Sheet1 which is not working.
https://drive.google.com/file/d/0B0s-0_lS3QrnMHZPZnlHd3lDRzg/view?usp=sharing
Thanks for your help.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCell As Range
Dim rRng1 As Range
Dim rRng2 As Range
Set rRng2 = Sheets("Data").Range("C2:F6")
On Error GoTo haveError
'see if any changes are in the monitored range...
Set rRng1 = Application.Intersect(Target, Me.Range("C1:C10"))
If Not rRng1 Is Nothing Then
'Next line prevents code updates from re-triggering this...
Application.EnableEvents = False
For Each rCell In rRng1.rCells
Debug.Print rCell.Address, rCell.Value
If rCell.Value <> "" Then
rCell.Offset(0, 1) = Application.VLookup(rCell, rRng2, 2, 0)
rCell.Offset(0, 2) = Application.VLookup(rCell, rRng2, 3, 0)
rCell.Offset(0, 3) = Application.VLookup(rCell, rRng2, 4, 0)
End If
Next
Application.EnableEvents = True
End If
Exit Sub