Problem with ComboBox in percentage

CouchKing

New Member
Joined
Jan 5, 2010
Messages
1
Hi all!
<o:p> </o:p>
I’m new to this forum and also VBA so be gentle! ;)<o:p></o:p>
<o:p> </o:p>
I have an excel sheet with a button linking to a form that gives input to a calculation done in the sheet.<o:p></o:p>
<o:p> </o:p>
One of the inputs in this form is ComboBox1. The source for this combobox is row AF1:AF13. This is formatted as a percentage i.e. 0 %, 5 %, 10 % and so on. In addition I’ve added the following code to the ComboBox:<o:p></o:p>
<o:p> </o:p>
Private Sub ComboBox1_Change()<o:p></o:p>
ComboBox1 = Format(ComboBox1, "##0 %")<o:p></o:p>
Range("C17") = ComboBox1.Value<o:p></o:p>
End Sub<o:p></o:p>
<o:p> </o:p>
This is my attempt at getting the correct formatting of the numbers in the form and in the excel sheet. However, I’m not getting the correct values in the form.<o:p></o:p>
<o:p> </o:p>
In the form when I select the value it’s displayed correctly, but not after selection. For example on selecting 10 % from the dropdown it’s displayed in the form as 0.10.<o:p></o:p>
<o:p> </o:p>
Other values again turn to a completely wrong number. For example selecting 20 % turns to 3655700 % in the form and the excel sheet.<o:p></o:p>
<o:p> </o:p>
Any tips from you guys would be appreciated!<o:p></o:p>
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Welcome to the board!

Set up a block of cells (AG1:AG13) adjacent to your numeric value cells (AF1:AF13), format them as text and put the appropriate text values in the cells adjacent to the numeric values.

Set the following properties of ComboBox1:
- Bound Column = 1 'Column that contains the value of the textbox
- TextColumn = 2 'Column that is displayed in the text box
- RowSource = Sheet1!AF1:AG13 'Be sure to define which sheet the data is in

This would be your combobox change code:
Code:
Private Sub ComboBox1_Change()
    Sheet1.Range("C17") = ComboBox1.Value
    Sheet1.Range("C17").NumberFormat = "##0 %" 'This should only need to be applied once and can be done manually rather than every time the combobox is updated.
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top