ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   combobox update (https://www.excelbanter.com/excel-programming/292099-combobox-update.html)

Josh[_9_]

combobox update
 
I have 2 modules with a combo box in each that I would like to have
update automatically. Module 1: company names, Module 2: Company 1 & 2
address. Right now if I select company 1, I get company 1 address. If
I select Company 2, I still have company 1 addresses. If I go into view
code and run the form, I get company 1 and company 2 addresses.

Here is a basic form of what I had, I shrunk them to save space. (There
is more companies and addresses than 2.)
Module 1
Public Sub Combobox1_DropButtonClick()
Dim arrCompany(1 To 2)
arrCompany(1) = "Company 1"
arrCompany(2) = "Company 2"
Dim Entrycount As Long
For Entrycount = 1 To 2
Worksheets("Template").ComboBox1.AddItem
arrCompany(Entrycount)
Next

End Sub

Module 2
Public Sub ComboBox2_DropButtonClick()

'Company 1
If Worksheets("Template").ComboBox1.Value = "Company 1" Then
Dim arrNTC(1 To 2)
arrNTC(1) = "Company 1 Address 1"
arrNTC(2) = "Company 1 Address 2"
Dim Entrycount1 As Long
For Entrycount1 = 1 To 2
Worksheets("Template").ComboBox2.AddItem
arrNTC(Entrycount1)
Next
End If

'Company 2
If Worksheets("Template").ComboBox1.Value = "Company 2" Then
Dim arrSTC(3 To 4)
arrSTC(3) = "Company 2 Address 1"
arrSTC(4) = "Company 2 Address 2"
Dim entrycount2 As Long
For entrycount2 = 3 To 4
Worksheets("Template").ComboBox2.AddItem
arrSTC(entrycount2)
Next
End If
End Sub

Any help would be greatly appreciated, I am still quite new to VB.

Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tom Ogilvy

combobox update
 
Public Sub ComboBox2_DropButtonClick()

Worksheets("Template").ComboBox2.Clear

'Company 1
If Worksheets("Template").ComboBox1.Value = "Company 1" Then
Dim arrNTC(1 To 2)
arrNTC(1) = "Company 1 Address 1"
arrNTC(2) = "Company 1 Address 2"
Dim Entrycount1 As Long
For Entrycount1 = 1 To 2
Worksheets("Template").ComboBox2.AddItem
arrNTC(Entrycount1)
Next
End If

'Company 2
If Worksheets("Template").ComboBox1.Value = "Company 2" Then
Dim arrSTC(3 To 4)
arrSTC(3) = "Company 2 Address 1"
arrSTC(4) = "Company 2 Address 2"
Dim entrycount2 As Long
For entrycount2 = 3 To 4
Worksheets("Template").ComboBox2.AddItem
arrSTC(entrycount2)
Next
End If
End Sub

--
Regards,
Tom Ogilvy


"Josh" wrote in message
...
I have 2 modules with a combo box in each that I would like to have
update automatically. Module 1: company names, Module 2: Company 1 & 2
address. Right now if I select company 1, I get company 1 address. If
I select Company 2, I still have company 1 addresses. If I go into view
code and run the form, I get company 1 and company 2 addresses.

Here is a basic form of what I had, I shrunk them to save space. (There
is more companies and addresses than 2.)
Module 1
Public Sub Combobox1_DropButtonClick()
Dim arrCompany(1 To 2)
arrCompany(1) = "Company 1"
arrCompany(2) = "Company 2"
Dim Entrycount As Long
For Entrycount = 1 To 2
Worksheets("Template").ComboBox1.AddItem
arrCompany(Entrycount)
Next

End Sub

Module 2
Public Sub ComboBox2_DropButtonClick()

'Company 1
If Worksheets("Template").ComboBox1.Value = "Company 1" Then
Dim arrNTC(1 To 2)
arrNTC(1) = "Company 1 Address 1"
arrNTC(2) = "Company 1 Address 2"
Dim Entrycount1 As Long
For Entrycount1 = 1 To 2
Worksheets("Template").ComboBox2.AddItem
arrNTC(Entrycount1)
Next
End If

'Company 2
If Worksheets("Template").ComboBox1.Value = "Company 2" Then
Dim arrSTC(3 To 4)
arrSTC(3) = "Company 2 Address 1"
arrSTC(4) = "Company 2 Address 2"
Dim entrycount2 As Long
For entrycount2 = 3 To 4
Worksheets("Template").ComboBox2.AddItem
arrSTC(entrycount2)
Next
End If
End Sub

Any help would be greatly appreciated, I am still quite new to VB.

Josh

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Josh[_9_]

combobox update
 
Tom

Worksheets("Template").ComboBox2.Clear


that so simple its embarassing. That has helped me with other problems
I was running into as well, thanks a lot for your help with this and
other problems I have come across.

Josh


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 03:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com