Roman Peterský
Roman Peterský

Reputation: 3

Split Date and String in Excel VBA

I'd need to get an amount of hours from data in the following format:

'166:05 hod:min'

The first number is the amount of hours, next after ':' are minutes. The rest can be thrown away.

My idea was to split the first number, add the second number divided by 60 [166:05 -> 166,08], but I'm the very beginner of VBA and these things.

Upvotes: 0

Views: 2631

Answers (1)

Nadeem_MK
Nadeem_MK

Reputation: 7689

You can simply use the Split command in VBA,

Dim splitTarget() As Variant
Dim splitMin() as Variant

splitTarget  = Split('166:05 hod:min', ":") 

splitTarget(0) should return 166 and splitTarget(1) should return '05 hod'

splitMin = Split(splitTarget(0), " ") 

SplitMin(0) will give you the 05

Upvotes: 1

Related Questions