Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default How to write Left Function in VB

Hi. I'm trying to programmatically write this line of code into a
macro:

=LEFT(A1,FIND("-",A1)-1)

The function shows all characters to the left of a hyphen. Anything
to the right and the hypen isn't displayed.

Ex. 12345-6789 shows as 12345

I'd like to use this function in code to highlight an entire column
like A:A and display the results in B:B.

I'd also like to ignore rows where no hyphen is found. Can anyone
help on this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to write Left Function in VB

I'm trying to programmatically write this line of code into a
macro:

=LEFT(A1,FIND("-",A1)-1)

The function shows all characters to the left of a hyphen. Anything
to the right and the hypen isn't displayed.

Ex. 12345-6789 shows as 12345

I'd like to use this function in code to highlight an entire column
like A:A and display the results in B:B.

I'd also like to ignore rows where no hyphen is found. Can anyone
help on this?


I would not use the LEFT function at all; the following will be much
quicker...

Sub GetTextBeforeHyphen()
Columns("B").Value = Columns("A").Value
Columns("B").Replace "-*", "", xlPart
End Sub

Rick Rothstein (MVP - Excel)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to write Left Function in VB

On Sep 22, 3:09*pm, "Rick Rothstein"
wrote:
I'm trying to programmatically write this line of code into a
macro:


=LEFT(A1,FIND("-",A1)-1)


The function shows all characters to the left of a hyphen. *Anything
to the right and the hypen isn't displayed.


Ex. *12345-6789 shows as 12345


I'd like to use this function in code to highlight an entire column
like A:A and display the results in B:B.


I'd also like to ignore rows where no hyphen is found. *Can anyone
help on this?


I would not use the LEFT function at all; the following will be much
quicker...

Sub GetTextBeforeHyphen()
* * Columns("B").Value = Columns("A").Value
* * Columns("B").Replace "-*", "", xlPart
End Sub

Rick Rothstein (MVP - Excel)


Thanks! I didn't imagine that to be so simple. How do I get this to
work even if certain rows are hidden with a filter?
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
How to nest a left function within a sumif function? LisaK Excel Worksheet Functions 2 April 23rd 23 11:46 AM
LEFT function-all to left of a comma? Jennifer F Excel Worksheet Functions 1 January 21st 09 11:19 PM
Over write a file someone has left opened. excelnut1954 Excel Programming 2 June 2nd 08 04:54 PM
Left vs Left$ function Andy Excel Discussion (Misc queries) 5 May 6th 07 04:06 AM
HOW DO I NEST THE VLOOKUP FUNCTION WITH THE LEFT FUNCTION CHAIM Excel Worksheet Functions 1 July 27th 05 09:10 PM


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

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

About Us

"It's about Microsoft Excel"