• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change listbox colomns to hh:mm

Hello everybody,
I need a bit of code to change column 7 and 8 into hh:mm in my listbox called ListofData
now I get decimals
The list is populated from Formulas -> Defined name list Called ListofData
file included
Thanks in advance
 

Attachments

  • Kopie van vbformulierwijzigingen.xlsb
    42.1 KB · Views: 3
Changed following.
1. Made ListofData dynamic using formula to populate range
=OFFSET(Invulblad!$A$3,0,0,COUNTA(Invulblad!$B:$B)-1,12)

Your original used static range and populated unnecessarily large range to the listbox (with empty cells).

2. Inserted following part after ".List = Myarray" Line
Code:
        For i = 0 To rng.Rows.Count - 1
                .List(i, 6) = (Format(Val(.List(i, 6)), "hh:mm"))
                .List(i, 7) = (Format(Val(.List(i, 7)), "hh:mm"))
        Next
Note that .List starts from 0. So Column 7 is referred to as .List(i, 6).

See attached.
 

Attachments

  • Kopie van vbformulierwijzigingen.xlsb
    43.5 KB · Views: 3
Hello Chihiro,
Thank you for you quick reply and answer. However, i get an error. I cleared the contens of the first (and only) row and then i got the error. I tried to solve it but i can't find a solution
 
Hmm? Do you mean that you want to load without any data upon Userform initialize?

Easiest way to get around that is to include header row.
 
Hello Chihiro,
Thank you again.
Yes, that is what i mean, i should be able to start with an empty sheet, exept for the header row (row 2)
the header row is row 2, i did not clear the contents of row 2 only of row3. I did not change anything else in the example file
 
Ok then. Change following.
1. ListofData Range formula adjusted to...
=OFFSET(Invulblad!$A$3,0,0,COUNTA(Invulblad!$B:$B),12)

2. Changed format code portion to only apply if rng.Rows.Count is greater than 1
Code:
        If rng.Rows.Count > 1 Then
            For i = 0 To rng.Rows.Count - 2
                    .List(i, 6) = (Format(Val(.List(i, 6)), "hh:mm"))
                    .List(i, 7) = (Format(Val(.List(i, 7)), "hh:mm"))
            Next
        End If
 

Attachments

  • Kopie van vbformulierwijzigingen_v2.xlsb
    43.5 KB · Views: 3
Hmm? Can you detail exactly when that happens?

I tested it by entering dummy data and had no issues.
upload_2016-5-3_13-41-23.png
 
Hoi,
This is wat i get
 
May be... but to my knowledge time format shouldn't change between languages.

Test by replacing "hh:mm" portion of the code with other variants such as "H:mm" and see what happens.
 
I give it a try tommorow and comeback to you
I saw the formula in the ListofData name reference was auto translated to dutch
Thanks for all the help until now
Have a good night
 
Try this workaround.

When adding items to Myarray. Use .Text of Cells. This should enter value as string and retain format. One side effect is that you will need to convert it back to Time Value if you need to do operation within VBA.

However, didn't see any operation done using these values in your code.

See attached.
 

Attachments

  • Kopie van vbformulierwijzigingen_v3.xlsb
    43.5 KB · Views: 10
Hello Chihiro,
Thank you for your reply and Solution.
The 3th version is working fine
Thank you for your patience and assistance
Greetz
(problem solved)
 
Back
Top