Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Extract data to the right of a hyphen in a cell


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


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534595

  #2   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 67
Default Extract data to the right of a hyphen in a cell

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

--
When you lose your mind, you free your life.
Ever Notice how we use '' for comments in our posts even if they aren''t
expected to go into the code?


"DavidW" wrote:


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


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534595


  #3   Report Post  
Posted to microsoft.public.excel.programming
ben ben is offline
external usenet poster
 
Posts: 67
Default Extract data to the right of a hyphen in a cell

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


--
When you lose your mind, you free your life.
Ever Notice how we use '' for comments in our posts even if they aren''t
expected to go into the code?


"ben" wrote:

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

--
When you lose your mind, you free your life.
Ever Notice how we use '' for comments in our posts even if they aren''t
expected to go into the code?


"DavidW" wrote:


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


--
DavidW
------------------------------------------------------------------------
DavidW's Profile: http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534595


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Extract data to the right of a hyphen in a cell

one way

GetRght = Right(Range("d4"), (InStr(1, Range("d4"), "-") + 1) - 1)


--


Gary


"ben" (remove this if mailing direct) wrote in message
...
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

--
When you lose your mind, you free your life.
Ever Notice how we use '' for comments in our posts even if they aren''t
expected to go into the code?


"DavidW" wrote:


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


--
DavidW
------------------------------------------------------------------------
DavidW's Profile:
http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534595




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Extract data to the right of a hyphen in a cell

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)

"DavidW" wrote in
message ...

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


--
DavidW
------------------------------------------------------------------------
DavidW's Profile:

http://www.excelforum.com/member.php...o&userid=32630
View this thread: http://www.excelforum.com/showthread...hreadid=534595





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace first hyphen in a cell Huber57 Excel Discussion (Misc queries) 8 June 3rd 09 07:13 PM
Adding hyphen to text in cell Penny[_2_] Excel Discussion (Misc queries) 6 March 25th 09 02:08 AM
Cell format - put hyphen where zero value would be. sheana New Users to Excel 2 February 1st 08 06:20 PM
hyphen (nit minus) in cell Appalachia Excel Discussion (Misc queries) 3 September 19th 07 01:39 PM
Entering a hyphen into a cell Goodwin Excel Worksheet Functions 1 March 30th 06 10:42 PM


All times are GMT +1. The time now is 07:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"