mardi 31 mars 2020

Use IF and VLOOKUP to change a cell value in VBA

I am trying to use Vlookup in VBA to change a value elsewhere in the sheet, based on the selection from a drop-down list.

I also want to combine this with an IF statement, so I want to select a calculated output number, if the valued looked up above is changed to 50%.

code is:

Dim nmcr_apalutamide_progress_num As Integer

Dim nmcr_apalutamide_ptc As Double

Range("nmcr_apalutamide_ptc").Value = 0.5

Dim result As Integer
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("model")


If Range("nmcr_apalutamide_ptc").Value = 0.5 Then
Range("result = Application.WorksheetFunction.VLookup(sheet.Range("nmcr_comparator_treatment"), sheet.Range("E52:H61"), 4, False)").Value = 0.5
'also change comparator percentage to 50%'


result = Application.WorksheetFunction.VLookup(sheet.Range("nmcr_comparator_treatment"), sheet.Range("D139:H146"), 5, False)
'find outcome comparator number'

End If

This shouldn't be that hard to do, I am not sure what I am missing.

Aucun commentaire:

Enregistrer un commentaire