Link to home
Start Free TrialLog in
Avatar of rutgermons
rutgermons

asked on

highlight entire selected range value row

Folks

I have a combo box that selects from values in column A

i.e.

A                               B
British Airways         UK
Qantas                      AUS
Lufthansa                 Germany

If I select from the list in the combo box, how can my macro then highlight the entire selected row in the excel sheet itself based on my choice

so if for example I select Qanta from colum a, both qantas and AUS will be highlighted in
Red
Avatar of yuppydu
yuppydu
Flag of Italy image

The combobox is in a form or on a sheet?
Avatar of rutgermons
rutgermons

ASKER

on a sheet

here is the code

Private Sub ComboBox1_gotfocus()
Dim r As Long

r = Sheet1.Range("A1").Offset(Sheet1.Rows.Count - 2, 0).End(xlUp).Row
    With ComboBox1
        .ColumnCount = 2
        .List = Range("A2:B" & r).Value
    End With

End Sub
I have named the upper left cell of the range as StartCell, then add this code:

Dim ItemPosition As Long

Private Sub ComboBox1_Click()
ItemCode = ComboBox1.List(ComboBox1.ListIndex, 1)
Sheet1.Range("StartCell").Offset(ItemCode, 0).Interior.ColorIndex = 36
Sheet1.Range("StartCell").Offset(ItemCode, 1).Interior.ColorIndex = 36
End Sub

Change the color as you wish. Yo can also use RGB and the command becomes .Interior.Color = RGB(200,160,35)
Sorry the Dim is: Dim ItemCode as Double
ASKER CERTIFIED SOLUTION
Avatar of samrad1
samrad1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
samrad

can u send me the vba code pls?
yuppudu,Im struggling wtih ur code,

u declare

Dim ItemPosition As Long



but dont reference it, where does this fit into my combobox code I specified?

all help will do
thanks for the solution, this wasnt a direct code fix in the macro but I used this sample and
opted the CF format instead and it works smoothly
rutgermons, I've added a comment right after the code posting saying that the Ddim was wrong and it shoud've been: Dim ItemCode as Double