use VBA to populate activex textbox with the value next to the cell searched for

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi there,

I have an activex combobox called ComboxC1. This is populated with a range of colours.
When a colour is chosen i want a textbox "TB1" to be populated with the result.

In sheet2 I have a series of different named ranges.
For TB1 the answer is contained in range "ColourFoundation".
The range is a table with two columns, in column one is the range of colours, column 2 has the results i want TB1 to be populated with depending on the colour. I hope this makes sense.

I know you can do this with a standard Vlookup formula but would much rather have a clean VBA code to do the job.

Thanks in advance for any help you can give,

Mike
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Seee if thid will fly

VBA Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
    For Each c In sh2.Range("ColourFoundation").Columns(1)
        If sh1.Range("C1").Interior.Color = c.Interior.Color Then
            sh1.TextBox("TB1").Value = c.Offset(, 1).Value
        End If
    Next
End Sub
 

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Seee if thid will fly

VBA Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
    For Each c In sh2.Range("ColourFoundation").Columns(1)
        If sh1.Range("C1").Interior.Color = c.Interior.Color Then
            sh1.TextBox("TB1").Value = c.Offset(, 1).Value
        End If
    Next
End Sub
Hi JLGWhiz,

Thanks very much for your help.
I think i didn't explain properly though.

the range and Combox has the words written, so it is text.
I managed to make it work though with the code below.

Thanks again for your help, it is really appreciated!

VBA Code:
Dim FindString As String
    Dim Rng As Range
    FindString = ComboxC1.Value
    If Trim(FindString) <> "" Then
        With Sheets("Sheet2").Range("ColourFoundation")
            Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
            If Not Rng Is Nothing Then
                TBox1.Value = Rng.Offset(, 1).Value
            Else
                MsgBox "Nothing found"
            End If
        End With
    End If
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Thanks for the feedback,
regards, JLG
 

Watch MrExcel Video

Forum statistics

Threads
1,128,018
Messages
5,628,166
Members
416,297
Latest member
Kara Payne

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
Top