# grab amt of days from cells

#### scott2000

##### New Member
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use \$ signs: \$V\$2:\$Z\$99 will always point to V2:Z99, even after copying

#### scott2000

##### New Member
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

#### Scott Huish

##### MrExcel MVP
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:

You are a god.

thank you.

Replies
12
Views
1K
Replies
7
Views
1K
Replies
6
Views
528
Replies
6
Views
325
Replies
5
Views
400

1,191,483
Messages
5,986,845
Members
440,053
Latest member
jhollingworth

### 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.

### Which adblocker are you using?

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

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