Error With Results Converting Text Date To Number

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I found this function through a Google search hoping to help me convert a text date (May 6, 2020) to a number that Excel can use.

Code:
Public Function GetDate1(ByVal rng As Range)
    GetDate = CDate(Left$(rng.Text, InStr(InStr(rng.Text, ", ") + 1, rng.Text, ", ") - 1))
End Function

With my example in cell A1 of my worksheet, the result I get when I enter (into another cell on the worksheet) =GetDate1(A1) is #VALUE!

Now I don't doubt it's an effective function, but I don't think I'm using it correctly. Unsure the purpose of the $ in the forumal. I suspect it needs to be tweaked somehow to recognize my value.
Suggestions?
 
AFAIK it works on hidden workbooks, what is your code?
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I think I know my problem Fluff, but unsure how to efficiently overcome it ..
I have this structure causing me the issue I think ...

Code:
Sub
    With workbook1.worksheet1
           open and hide new workbook2 (wb_rmr1)
           With wb_rmr1.worksheet1
                  Apply TextToColumns and other worksheet (wb_rmr.worksheet1) changes
           End With
    End With
End Sub

I don't think I can nest like that. I'm working through that understanding. I figure if I got rid of that nesting I'd be ok.
 
Upvote 0
Try it like
VBA Code:
 With wb_rmr1.Sheets("sheet1")
      .Range("A:A").TextToColumns Destination:=.Range("A1"), DataType:=xlDelimited, _
         TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
         Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
         :=Array(1, 3), TrailingMinusNumbers:=True
   End With
 
Upvote 0
Fluff, that works. :)
Thanks. This thread was chocked full of teachings.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,867
Members
449,130
Latest member
lolasmith

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