Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 65
Default VBA code needed

i am trying to retrieve a range of data (the stock code of different phones)
from worksheet("Inventory") based on the name of the branches of where the
phones are stored.

worksheet("Inventory") has branch (Column A) and stock code (Column B)

i have 2 combobox.
combobox1 contains values (name of branches) such as:
1-BS
2-EN
3-HG
4-JE
5-SP
6-TB
7-WS
8-YT

combobox2 will have to retrieve values from the worksheet("Inventory") based
on the value in combobox1. the values in combobox1 can be found in column 1
while the values i need for combobox2 can be retrieved from column 2 of
Inventory. however, i have many values for each branch, for example, i have
many 1-BS and there are many stock codes linked to 1-BS. how to retrieve all
the stock code of that particular branch?

Thanks.

--
help me
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 35,218
Default VBA code needed

In the combobox1_change procedure, you could loop through column A and if it
matches values, then add a new item to combobox2.

Option Explicit
Private Sub ComboBox1_Change()
Dim myRng As Range
Dim myCell As Range

If Me.ComboBox1.ListIndex < 0 Then
Exit Sub 'nothing chosen
End If

With Worksheets("Inventory")
Set myRng = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ComboBox2
.Clear
For Each myCell In myRng.Cells
If LCase(myCell.Value) = LCase(Me.ComboBox1.Value) Then
.AddItem myCell.Offset(0, 1).Value
End If
Next myCell
End With

End Sub
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()

With Me.ComboBox1
.RowSource = ""
.Clear
'just some test data
.AddItem "A1"
.AddItem "A2"
.AddItem "A3"
.AddItem "A4"
End With

End Sub


ernie wrote:

i am trying to retrieve a range of data (the stock code of different phones)
from worksheet("Inventory") based on the name of the branches of where the
phones are stored.

worksheet("Inventory") has branch (Column A) and stock code (Column B)

i have 2 combobox.
combobox1 contains values (name of branches) such as:
1-BS
2-EN
3-HG
4-JE
5-SP
6-TB
7-WS
8-YT

combobox2 will have to retrieve values from the worksheet("Inventory") based
on the value in combobox1. the values in combobox1 can be found in column 1
while the values i need for combobox2 can be retrieved from column 2 of
Inventory. however, i have many values for each branch, for example, i have
many 1-BS and there are many stock codes linked to 1-BS. how to retrieve all
the stock code of that particular branch?

Thanks.

--
help me


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code Needed John Calder New Users to Excel 10 July 15th 09 11:42 PM
Help needed with VBA code Sam Hill Excel Discussion (Misc queries) 1 May 9th 06 02:29 PM
VBA code help needed Martin Excel Discussion (Misc queries) 3 April 28th 06 09:28 AM
VLOOKUP code needed please j4ymf Excel Worksheet Functions 4 March 12th 06 07:48 PM
VBA code to sum a row: syntax needed [email protected] Excel Discussion (Misc queries) 1 July 11th 05 06:41 PM


All times are GMT +1. The time now is 04:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"