View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Rech[_2_] Jim Rech[_2_] is offline
external usenet poster
 
Posts: 533
Default Vlookup - Issue....

strAccountWeek = ComboBox2.Value

The "Value" of a combobox is what is displayed in it. But Vlookup needs an
'offset' number. So you should use the combo box's ListIndex property (+1)
rather than its Value property.

--
Jim
"veeraan" wrote in message
...
Hi,

I need help....

I have a worksheet which looks like this...

StoreNo--- 201 202 203

Week 1 X

Week 2 y

Week 3 z



I have two combobox's on main sheet where users can select Week's and
Store
numbers.

So say I can select Week 1 and Store 201.

Once users have selected these two variables , they click on a button and
the corresponding data should be populated in a textbox . So when I click
the
button , the output in textbox should be 'X' for above example.

I have the following code in button click event:

Dim strStoreNumber As String
Dim strAccountWeek As String
Dim rngLookup As Range
Dim varVlookupVarient As Variant

Private Sub CommandButton1_Click()

strStoreNumber = ComboBox1.Value
strAccountWeek = ComboBox2.Value

Set rngLookup =
Application.Workbooks("POS.xls").Worksheets("Sheet 1").Range("A:DW")

' this doesnt work....
varVlookupVarient = Application.VLookup(strAccountWeek, rngLookup,
ComboBox1.Value, False)

' Below line works but I need the column in Vlookup to be dynamically
selected.....
'varVlookupVarient = Application.VLookup(strAccountWeek, rngLookup, 2,
False)

MsgBox ("This is what you get" & varVlookupVarient)
' Once I get this data right, I can then have this as TextBox.value.

End Sub


Please help.....

I am not sure if I am doing this right...is there another way instead of
using Vlookups...

Regards
Veeraan