Excel/VBA coding

Advertisement


Question
Dear Aidan,
Please help me. I wanted to retrive information based on two combobox like, For eg: I have my name in combobox1 and combobox2 drops down list of files under my name. Like file1,2 etc.. if I choose file1 and press CommandButton1 then it should populate the information from that purticular row.

Currently it is working for combobox1 only how can I add another criteria for Combobox2.

Private Sub CommandButton1_Click()
row_number = 0
Do
DoEvents
row_number = row_number + 1
item_in_review = Sheets("Sheet1").Range("A" & row_number)
   If item_in_review = ComboBox1.Value Then
       TextBox1.Text = Sheets("Sheet1").Range("C" & row_number)
       TextBox4.Text = Sheets("Sheet1").Range("D" & row_number)
       TextBox2.Text = Sheets("Sheet1").Range("A" & row_number)
       TextBox3.Text = Sheets("Sheet1").Range("e" & row_number)
   End If

Loop Until item_in_review = ""
End Sub

Thank you very much in advance for your time and help.
Aji

Answer
I wouldn't bother with the item_in_review variable as it gives one extra line

  If Sheets("Sheet1").Range("A" & row_number) = ComboBox1.Value and Sheets("Sheet1").Range("B" & row_number) = ComboBox2.Value Then
      TextBox1.Text = Sheets("Sheet1").Range("C" & row_number)
      TextBox4.Text = Sheets("Sheet1").Range("D" & row_number)
      TextBox2.Text = Sheets("Sheet1").Range("A" & row_number)
      TextBox3.Text = Sheets("Sheet1").Range("e" & row_number)
  End If

is what I think you were asking for - though I may have mis-understood?
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Aidan Heritage

Expertise

I have provided first hand support since `95 for Microsoft Office majoring in Word and Excel - support for all versions from 2 onwards. I'm based in the UK, so please allow for time differences when asking me questions from other parts of the world!

Experience

My background is in the insurance industry and call centre areas, but have been called upon to provide many varied solutions.

Education/Credentials
I'm educated to UK A level standard, but as I left school some 30 years ago that is rather irrelevent - university of life has provided more of a background!

©2016 About.com. All rights reserved.