Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default ControlSource Errors with 2-Column ComboBox

I have been having the same issue for a while now, and it is now time
for me to conquer this problem, so I made a new simple spreadsheet with
ONLY the combobox and the appropriate code to try to single out the
problem.

I have a list of numbers in cells A1:A12, and the cell that stores the
ComboBox value is C1.

I have a UserForm with 1 combobox on it. The combobox has 2 columns,
the first column shows formatted numbers, the 2nd column is invisible
and contains the numbers without any formatting. The 2nd column is the
bound column.

The code below is all the code I have in my entire worksheet:


Private Sub ComboBox1_Change()

Worksheets("Sheet1").Cells(1, 3).Value = UserForm1.ComboBox1.Value

End Sub


Private Sub UserForm_Initialize()

If UserForm1.ComboBox1.ListCount 0 Then
Else

With UserForm1.ComboBox1
.ControlSource = "C1"
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "-1;0"

For j = 1 To 12
.AddItem Format((Worksheets("Sheet1").Cells(j, 1).Value),
"#0.000")
.List(.ListCount - 1, 1) = Worksheets("Sheet1").Cells(j,
1).Value
Next j
End With
End If

End Sub


THE ISSUE: There is a flaw with the design of my code where when you
open the UserForm, it clears the "ControlSource" value in the
spreadsheet and shows a blank value until I select a new value. I need
it to just show the value that was in "C1" and not erase it...

Does anybody see any design flaws in my code that could be attributing
to this problem?

Thanks in advance!!!
Justin

PS -- The ComboBox has NO properties set other than what comes default
in Excel 2000.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ControlSource Errors with 2-Column ComboBox

Private Sub UserForm_Initialize()
Dim v

v = Worksheets("sheet1").Range("C1").Value
With UserForm1.ComboBox1
.ControlSource = "Sheet1!C1"
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "-1;0"

For j = 1 To 12
.AddItem Format((Worksheets("Sheet1").Cells(j, 1).Value),
"#0.000")
.List(.ListCount - 1, 1) = Worksheets("Sheet1").Cells(j,
1).Value
Next j
End With
Userform.Combobox1.Value = v


End Sub

get rid of the change event. You already use the controlsource property to
update the cell.

--
Regards,
Tom Ogilvy


"Justin" wrote:

I have been having the same issue for a while now, and it is now time
for me to conquer this problem, so I made a new simple spreadsheet with
ONLY the combobox and the appropriate code to try to single out the
problem.

I have a list of numbers in cells A1:A12, and the cell that stores the
ComboBox value is C1.

I have a UserForm with 1 combobox on it. The combobox has 2 columns,
the first column shows formatted numbers, the 2nd column is invisible
and contains the numbers without any formatting. The 2nd column is the
bound column.

The code below is all the code I have in my entire worksheet:


Private Sub ComboBox1_Change()

Worksheets("Sheet1").Cells(1, 3).Value = UserForm1.ComboBox1.Value

End Sub


Private Sub UserForm_Initialize()

If UserForm1.ComboBox1.ListCount 0 Then
Else

With UserForm1.ComboBox1
.ControlSource = "C1"
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "-1;0"

For j = 1 To 12
.AddItem Format((Worksheets("Sheet1").Cells(j, 1).Value),
"#0.000")
.List(.ListCount - 1, 1) = Worksheets("Sheet1").Cells(j,
1).Value
Next j
End With
End If

End Sub


THE ISSUE: There is a flaw with the design of my code where when you
open the UserForm, it clears the "ControlSource" value in the
spreadsheet and shows a blank value until I select a new value. I need
it to just show the value that was in "C1" and not erase it...

Does anybody see any design flaws in my code that could be attributing
to this problem?

Thanks in advance!!!
Justin

PS -- The ComboBox has NO properties set other than what comes default
in Excel 2000.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default ControlSource Errors with 2-Column ComboBox

You got it! Thanks so much Tom!


Tom Ogilvy wrote:
Private Sub UserForm_Initialize()
Dim v

v = Worksheets("sheet1").Range("C1").Value
With UserForm1.ComboBox1
.ControlSource = "Sheet1!C1"
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "-1;0"

For j = 1 To 12
.AddItem Format((Worksheets("Sheet1").Cells(j, 1).Value),
"#0.000")
.List(.ListCount - 1, 1) = Worksheets("Sheet1").Cells(j,
1).Value
Next j
End With
Userform.Combobox1.Value = v


End Sub

get rid of the change event. You already use the controlsource property to
update the cell.

--
Regards,
Tom Ogilvy


"Justin" wrote:

I have been having the same issue for a while now, and it is now time
for me to conquer this problem, so I made a new simple spreadsheet with
ONLY the combobox and the appropriate code to try to single out the
problem.

I have a list of numbers in cells A1:A12, and the cell that stores the
ComboBox value is C1.

I have a UserForm with 1 combobox on it. The combobox has 2 columns,
the first column shows formatted numbers, the 2nd column is invisible
and contains the numbers without any formatting. The 2nd column is the
bound column.

The code below is all the code I have in my entire worksheet:


Private Sub ComboBox1_Change()

Worksheets("Sheet1").Cells(1, 3).Value = UserForm1.ComboBox1.Value

End Sub


Private Sub UserForm_Initialize()

If UserForm1.ComboBox1.ListCount 0 Then
Else

With UserForm1.ComboBox1
.ControlSource = "C1"
.ColumnCount = 2
.BoundColumn = 2
.ColumnWidths = "-1;0"

For j = 1 To 12
.AddItem Format((Worksheets("Sheet1").Cells(j, 1).Value),
"#0.000")
.List(.ListCount - 1, 1) = Worksheets("Sheet1").Cells(j,
1).Value
Next j
End With
End If

End Sub


THE ISSUE: There is a flaw with the design of my code where when you
open the UserForm, it clears the "ControlSource" value in the
spreadsheet and shows a blank value until I select a new value. I need
it to just show the value that was in "C1" and not erase it...

Does anybody see any design flaws in my code that could be attributing
to this problem?

Thanks in advance!!!
Justin

PS -- The ComboBox has NO properties set other than what comes default
in Excel 2000.



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
ComboBox Decimal Errors Tyler[_3_] Excel Programming 0 September 6th 06 07:39 PM
MAX value of a column that has #div/0 errors in it Ray Elias Excel Discussion (Misc queries) 2 April 24th 06 03:47 PM
Controlsource errors Mats Samson Excel Programming 7 August 4th 05 04:49 PM
Setting ComboBox ControlSource in code JimPNicholls Excel Programming 4 August 23rd 04 10:44 AM
question about the ControlSource of a ComboBox delaney_55 Excel Programming 2 April 18th 04 03:56 PM


All times are GMT +1. The time now is 12:34 AM.

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

About Us

"It's about Microsoft Excel"