how to substitute a column reference for an If statement

Glenn C

New Member
Joined
May 23, 2019
Messages
4
Hi

sht = Me.ComboBox15.ValueIf Sheets(sht).Cells(i, "A").Value = (sht) Or _
Sheets(sht).Cells(i, "A").Value = productCode Then
Me.TextBox13 = Format(Sheets(sht).Cells(i, "C").Value, "0.00")

I have the above Syntax that looks up a value on a worksheet, it works fine, but I would like to substitute the "C" (column reference) for this dynamic nested If statement:

If ComboBox5 = "closed top" Then
TextBox100 = "C"
ElseIf ComboBox5 = "open top" Then
TextBox100 = "D"
ElseIf ComboBox5 = "over height" Then
TextBox100 = "E"
ElseIf ComboBox5 = "Jumbo" Then
TextBox100 = "F"
End If


Thanks for any help!!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this


Code:
    If ComboBox5 = "closed top" Then
        TextBox100 = "C"
    ElseIf ComboBox5 = "open top" Then
        TextBox100 = "D"
    ElseIf ComboBox5 = "over height" Then
        TextBox100 = "E"
    ElseIf ComboBox5 = "Jumbo" Then
        TextBox100 = "F"
    End If
    
    If TextBox100 <> "" Then
        sht = Me.ComboBox15.Value
        If Sheets(sht).Cells(i, "A").Value = (sht) Or _
            Sheets(sht).Cells(i, "A").Value = ProductCode Then
            Me.TextBox13 = Format(Sheets(sht).Cells(i, TextBox100).Value, "0.00")
        End If
    End If
 
Upvote 0
Hi
Thanks Dante, sorry I should have mentioned that I’m trying to do without textbox100 and just put that formula into the code for text box13 (where it currently referenced “C”)
 
Upvote 0
Hi
Thanks Dante, sorry I should have mentioned that I’m trying to do without textbox100 and just put that formula into the code for text box13 (where it currently referenced “C”)

Then change it by any variable

Code:
    If ComboBox5 = "closed top" Then
       [COLOR=#0000ff]varx [/COLOR]= "C"
    ElseIf ComboBox5 = "open top" Then
        [COLOR=#0000ff]varx[/COLOR] = "D"
    ElseIf ComboBox5 = "over height" Then
        [COLOR=#0000ff]varx [/COLOR]= "E"
    ElseIf ComboBox5 = "Jumbo" Then
        [COLOR=#0000ff]varx [/COLOR]= "F"
    End If
    
    If [COLOR=#0000FF]varx [/COLOR] <> "" Then
        sht = Me.ComboBox15.Value
        If Sheets(sht).Cells(i, "A").Value = (sht) Or _
            Sheets(sht).Cells(i, "A").Value = ProductCode Then
            Me.TextBox13 = Format(Sheets(sht).Cells(i, [COLOR=#0000ff]varx[/COLOR]).Value, "0.00")
        End If
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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