Duration Calculation

ksilvan0418

New Member
Joined
Dec 17, 2014
Messages
6
I am looking for VBA code to perform the following task..

I have a column for baseline duration, a column for duration and a column for production coding.

I need code to auto figure the following… duration = baseline duration * production coding.

My issue is that both the duration and baseline duration have text and numbers in it. (i.e. 1.5 hrs, 1 day, etc). These columns cannot be split. Production coding only has a number (1, 2, 3, 4 or 5).


Please help!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Care to provide say, 8-10 rows of data (that represent a good sample of what you currently have)?
 
Upvote 0
Duration
Baseline Duration
Production Coding

1.5 hrs
2

1.5 hrs
1

2 days
1

2 days
2

3 hrs
3

4 hrs
2


<tbody>
</tbody>
 
Upvote 0
Sub DurationCalculation()
'Calculate duration based off of Production Coding
If Summary = No Then
Duration = Duration1 * Number1
End If
End Sub

What I wrote so far.
 
Upvote 0
This ought to do the trick.
=LEFT(B2,FIND(" ",B2))*C2


Update:
*** Oh, sorry, did you still want VBA Code?
 
Upvote 0
Yes! Definitely... I usually can do it, but this one really has me stumped!
Something like this?
Code:
Sub Duration()    lastRow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
    For x = 2 To lastRow
        Range("A" & x).Value = Left(Range("B" & x).Value, InStr(1, Range("B" & x).Value, " ", vbTextCompare)) * Range("C" & x).Value
    Next x
End Sub
 
Upvote 0
It works fine for me
In what way does it not work for you?
Do you get an error? What Error?
Do you get the wrong result? What result DO you get, what result did you expect?

Note that something happened to Gilliam's post, that the first 2 lines of the code got put on the same line..
I don't know why that happens sometimes on this (and some other) forums.

So the first line
Sub Duration() lastRow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row

Should be seperated like
Sub Duration()
lastRow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,217,241
Messages
6,135,439
Members
449,933
Latest member
fernandy772

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