Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default truncation problem


Can someone help me with this. I've been away from VBA for over 2 year
and my mind is rusty.

I have a range selected that will be letters, then numbers as one word
I want to add a hypthen in between the letters and numbers. How can i d
this VBA wise?

Ex.

abc123 - abc-123
ghj1234 - ghj-1234
wa76 - wa-76

Thanks alot guys,
mb

--
mbk14
-----------------------------------------------------------------------
mbk141's Profile: http://www.excelforum.com/member.php...fo&userid=1575
View this thread: http://www.excelforum.com/showthread.php?threadid=27267

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default truncation problem

I'd do something like:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range
Dim iCtr As Long

Set myRng = Selection

For Each myCell In myRng.Cells
With myCell
For iCtr = 1 To Len(.Value)
If IsNumeric(Mid(.Value, iCtr, 1)) Then
.Value = Left(.Value, iCtr - 1) & "-" & Mid(.Value, iCtr)
Exit For
End If
Next iCtr
End With
Next myCell
End Sub



mbk141 wrote:

Can someone help me with this. I've been away from VBA for over 2 years
and my mind is rusty.

I have a range selected that will be letters, then numbers as one word.
I want to add a hypthen in between the letters and numbers. How can i do
this VBA wise?

Ex.

abc123 - abc-123
ghj1234 - ghj-1234
wa76 - wa-76

Thanks alot guys,
mbk

--
mbk141
------------------------------------------------------------------------
mbk141's Profile: http://www.excelforum.com/member.php...o&userid=15757
View this thread: http://www.excelforum.com/showthread...hreadid=272676


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default truncation problem

On Tue, 26 Oct 2004 19:57:07 -0500, mbk141
wrote:


Can someone help me with this. I've been away from VBA for over 2 years
and my mind is rusty.

I have a range selected that will be letters, then numbers as one word.
I want to add a hypthen in between the letters and numbers. How can i do
this VBA wise?

Ex.

abc123 - abc-123
ghj1234 - ghj-1234
wa76 - wa-76

Thanks alot guys,
mbk


There are probably better ways, but this should work:

==============
Function InsertHyphen(str As String)
Dim i As Integer

For i = 1 To Len(str)
If IsNumeric(Mid(str, i, 1)) Then Exit For
Next i

InsertHyphen = Left(str, i - 1) & "-" & Right(str, Len(str) - i + 1)

End Function
=====================


--ron
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
truncation of y-axis text Trainman Charts and Charting in Excel 2 March 15th 06 10:14 AM
Print truncation sbweid Excel Discussion (Misc queries) 0 November 8th 05 04:25 PM
Copy range content as picture - truncation problem Jon Peltier[_8_] Excel Programming 0 July 22nd 04 09:17 PM
Copy range content as picture - truncation problem Ron de Bruin Excel Programming 0 July 22nd 04 01:27 PM
string truncation ljorn Excel Programming 0 September 11th 03 02:23 PM


All times are GMT +1. The time now is 08:58 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"