Extract data to the right of a hyphen in a cell

  • Thread starter Thread starter DavidW
  • Start date Start date
D

DavidW

I'm attempting to extract the data in a cell to the right of a
hyphen("-") and place it in a variable. I thought I could use the code
below, but it causes a compile error "Function or Sub not defined". The
word "Find" is highlighted and seems to be causing the error.

Does anyone have any suggestions? Once I get past the error, I might
have to adjust the code to make sure I'm getting the data I want.
Thanks

The contents of D4 is "9/1/2005-3/31/2006".
I need the "3/31/2006".
The workbook has multiple sheets. The cell I want is on worksheet
"Report Current".


Code:
--------------------
Sub Getit()
Dim GetRight As String
Worksheets("Report Current").Select
GetRight = (Right(D4, Len(D4), Find("" - "", D4) - 1))
End Sub
 
Sub Getit()
Dim GetRight As String
Worksheets("Report Current").Select
GetRight = (Right(D4, Len(D4), Find("" - "", D4) - 1))
GetRight = right(range("D4"),len(range("D4")-instr(1,range("D4"),"-"))
End Sub
 
sorry forgot to delete other line


Sub Getit()
Dim GetRight As String
Worksheets("Report Current").Select
GetRight = right(range("D4"),len(range("D4")-instr(1,range("D4"),"-"))
End Sub
 
Sub Getit()
Dim GetRight As String
Worksheets("Report Current").Select
GetRight = Right(Range("D4").Value, Len(Range("D4").Value) - _
InStr(Range("D4").Value, "-"))
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top