VBA equivalent to TEXT

andrewb90

Well-known Member
Joined
Dec 16, 2009
Messages
1,077
Hi all

I have this code:
Code:
Order00a.ComboBox4.List = Range("QTIME").Value
Order00a.ComboBox4.ListIndex = 0

My issue is, the values in the range are formatted as time, and when they appear in my combobox, they are decimals. How do I adjust this?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Re: VBA equivillent to TEXT

Hi all

I have this code:
Code:
Order00a.ComboBox4.List = Range("QTIME").Value
Order00a.ComboBox4.ListIndex = 0

My issue is, the values in the range are formatted as time, and when they appear in my combobox, they are decimals. How do I adjust this?


Hi,

try using the Range.Text property


Rich (BB code):
Order00a.ComboBox4.List = Range("QTIME").Text
Order00a.ComboBox4.ListIndex = 0

Dave
 
Upvote 0
Re: VBA equivillent to TEXT

I get run time error 381
Invalid property array index/.
 
Upvote 0
Re: VBA equivillent to TEXT

Hi all

I have this code:
Code:
Order00a.ComboBox4.List = [B][COLOR="#FF0000"]Format([/COLOR][/B]Range("QTIME").Value[B][COLOR="#FF0000"], "h:mm")[/COLOR][/B]
Order00a.ComboBox4.ListIndex = 0

My issue is, the values in the range are formatted as time, and when they appear in my combobox, they are decimals. How do I adjust this?
See if adding what I show in red above does what you want.
 
Upvote 0
Re: VBA equivillent to TEXT

I get run time error 381
Invalid property array index/.

Oops sorry about that - only glanced at your code & did not note you were using the List property of combobox

This seems a bit busy but maybe this will help

Code:
    Dim Cell As Range, QTIME As Range
    Dim arr() As String, i As Integer
    Set QTIME = Range("QTIME")
    ReDim arr(1 To QTIME.Cells.Count)
    For Each Cell In QTIME
        i = i + 1
        arr(i) = Cell.Text
    Next Cell


    Me.ComboBox4.List = arr

Dave
 
Upvote 0
Re: VBA equivillent to TEXT

I get a type mismatch error.
Are you replying to Rick or Dave? and on what line are you getting the type mismatch error?
 
Last edited:
Upvote 0
Re: VBA equivillent to TEXT

that was replying to Rick. the error was on the line with the QTIME format.
 
Upvote 0
Re: VBA equivillent to TEXT

that was replying to Rick. the error was on the line with the QTIME format.
I just realized that QTIME is a range of cells, not a single cell reference. Try using this line of code to assign your list of times to your ComboBox...

Order00a.ComboBox4.List = [IF({1},TEXT(QTIME,"h:mm"))]
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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