If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Combo Box on Startup

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-07, 06:03
JezLisle JezLisle is offline
Registered User
 
Join Date: Apr 2007
Location: Stalybridge, Manchester
Posts: 273
Combo Box on Startup

Hi, I have this code below that auto fills as Combo Box when the Spreadsheet Opens. It works great, but there is one issue I have with it. As if the Combo Box is changed once the Spreadsheet is open then it auto changes the cell on a particular worksheet. I have tried calling this function from the workbook open but just doesnt work. How can I get around this?

Private Sub Workbook_Open()
Application.ScreenUpdating = False
Dim intCount As Integer
'Populate Multi Column Combo Box - Installs Report
'***************************************
With Sheet1.cboInstallMonths
.Visible = False
.Clear
.ColumnCount = 2
.ColumnWidths = 0
.AddItem "1"
.List(.ListCount - 1, 1) = "January"
For intCount = 2 To 12 '
.AddItem (intCount)
.List(.ListCount - 1, 1) = MonthName(intCount)
Next
.Value = Val(DatePart("m", VBA.Date - 1))
.Visible = True
End With
With Sheet1
Select Case .cboInstallMonths.Value
Case 3, 6, 9, 12
booWeekType = True
Case Else
booWeekType = False
End Select
End With
End Sub

This is on the relevant Worksheet

Private Sub cboInstallMonths_Change()
On Error GoTo Err:
Application.ScreenUpdating = False
Sheet1.Cells(1, 1).Select
Select Case Sheet1.cboInstallMonths
Case 1
Call FourWeekMonth(1)
Case 2
Call FourWeekMonth(5)
Case 3
Call FiveWeekMonth(9)
Case 4
Call FourWeekMonth(14)
Case 5
Call FourWeekMonth(18)
Case 6
Call FiveWeekMonth(22)
Case 7
Call FourWeekMonth(27)
Case 8
Call FourWeekMonth(31)
Case 9
Call FiveWeekMonth(35)
Case 10
Call FourWeekMonth(40)
Case 11
Call FourWeekMonth(44)
Case 12
Call FiveWeekMonth(48)
End Select
Range("A1").Select
Err:
End Sub

Sub FiveWeekMonth(intStartWeek As Integer)
Sheet1.Cells(8, 4) = intStartWeek
'unhide 5th week column
Columns("T:W").Select
Selection.EntireColumn.Hidden = False
'hide 4 week total column
Columns("Y:AB").Select
Selection.EntireColumn.Hidden = True
'unhide 5 week total column
Columns("AC:AF").Select
Selection.EntireColumn.Hidden = False
'Columns("S:U").Select
'Selection.EntireColumn.Hidden = False
Range("A1").Select
Sheet1.Cells(8, 29) = VBA.MonthName(Sheet1.cboInstallMonths, True)
Range("G,K,O,S,W,AF,AK").ColumnWidth = 8
Call basPublic.InstallsSize5Week
booWeekType = True
Range("A1").Select
End Sub

Sub FourWeekMonth(intStartWeek As Integer)
Sheet1.Cells(8, 4) = intStartWeek
'hide 5 week column
Columns("T:W").Select
Selection.EntireColumn.Hidden = True
'unhide 4 week total column
Columns("Y:AB").Select
Selection.EntireColumn.Hidden = False
'hide 5 week total column
Columns("AC:AF").Select
Selection.EntireColumn.Hidden = True
Range("A1").Select
Sheet1.Cells(8, 25) = VBA.MonthName(Sheet1.cboInstallMonths, True)
Range("G,K,O,S,AB,AK").ColumnWidth = 8
Call basPublic.InstallsSize4Week
booWeekType = False
Range("A1").Select
End Sub
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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