grab amt of days from cells

scott2000

New Member
Joined
Apr 16, 2008
Messages
27
I have a column of cells with due dates, that look like:

5 days prior
2 days prior
2 weeks prior
1-3 days prior

I need to get the number of days, and change if its listed as weeks, or in the case of the 1-3 (or similar), the larger of the numbers...

I am clueless on this one! I appreciate any help!

cheers.:)
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I've come up with below to get rid of the 'days prior' or 'weeks prior' to give me just the numbers, but I don't know how to deal with the cells that say
4-7 prior days
since when i strip 'prior days' off, it gives me a large number instead.

Here is what I have:

Code:
    For Each myCell In dRange
    myCell.NumberFormat = "0"
    If Right(myCell, 10) = "days prior" Then
        myCell.Value = Left(myCell, Len(myCell) - 10)
    ElseIf Right(myCell, 9) = "wks prior" Then
        myCell.Value = Left(myCell, Len(myCell) - 9) * 7
    End If
    Next
Any ideas?
Thanks! Thanks! for any help
 
Upvote 0
Perhaps:

Code:
Sub test()
Dim c As Range, t As Integer
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    t = 1
    If InStr(c, "week") > 0 Then t = 7
    c.Offset = MaxNumber(c.Text) * t
Next
End Sub
 
Function MaxNumber(r As String)
Dim m As Object
With CreateObject("vbscript.regexp")
    .Pattern = "\d+ |-"
    .Global = True
    If .test(r) Then
        Set m = .Execute(r)
        MaxNumber = m(m.Count - 1)
    End If
End With
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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