Combobox data type
-
Still struggling with my combobox on a userform. My latest question is around Data Type. I am using a For/Next loop through several columns in a worksheet and call a userform containg a combobox to allow the user to enter data into the worksheet. In some cases the combobox contains multiple items from prepopulated named ranges. The user selects the correct item from the list (these are always text). The worksheet also contains Date columns, Numeric Columns, and Percentage columns and the user just types the appropriate entry into the empty combobbox. When I try to transfer the data from the combobox to the worksheet I need it to transfer as the correct data type. I am currently using a cells.value= combobox.value statement but everything is being entered as text or Number Stored as text. I can use a Select Case statement for the various column titles to modify the different entries but I can't seem to get the correct data type into the worksheet. Is there a way to set the data type (and hopefully the format) when posting the combobox entry to the worksheet?
-
Answer:
Steve, The value of the combobox will always be text You would need to do the conversion to make it the data type you want. below is some pseudo code. Instead of the column header, I used the column number, but you could do it however you want. I just demo the conversion. To write good code, you would need to validate the entry to make sure it can be converted to the type you want (the user has provided a valid entry) so instead of Case 10 cells(rw,col).value = cdate(combobox1.value) . . . you might have Case 10 if isdate(combobox1.valueO then cells(rw,col).value = cdate(combobox1.value) cells(rw,col).Numberformat = "mm/dd/yyyy" else msgbox combobox1.value & " is not a valid date entry" end if col = 10 select case col case 10 ' date cells(rw,col).value = cdate(combobox1.value) cells(rw,col).Numberformat = "mm/dd/yyyy" case 11 ' numeric cells(rw,col).value = cdbl(combobox1.value) case 12 ' percentage s = replace(combobox1.value,"%") cells(rw,col).value = cdbl(s)/100 case else cells(rw,col).value = combobox1.value end select
Miningco.com Visit the source
Related Q & A:
- How would you transfer data between your data structures and databases?Best solution by Programmers
- How to store data in php and get data from php?Best solution by Stack Overflow
- What are some good "beginner level" data modeling/analytics approaches to kick start a data science/analytics team?Best solution by Quora
- What are some phones for Verizon Wireless without a data plan or with a cheap data plan?Best solution by Yahoo! Answers
- What's the difference between a static data member and a regular data member?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.