Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Measure Text and insert underscore.

Hello,

I have a requirement that for a specfic font whenever I am provided some
text in random cell i measure the text and insert _ symbol.

for ex.
____________________
My Name is Rahul Gupta
____________________

Please help.

Regards,
Rahul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Measure Text and insert underscore.

Here is some demo code that you can modify as needed:

Sub gupta()
Dim s As String
For Each r In Selection
If r.Font.Name = "Arial" Then
s = r.Value
l = Len(s)
If l 2 Then
s = Left(s, 2) & "_" & Right(s, l - 2)
r.Value = s
End If
End If
Next
End Sub

Select a range of cells and run the macro. It looks for cells with the
Arial font and insters an underscore after the second character.
--
Gary's Student


"Rahul Gupta" wrote:

Hello,

I have a requirement that for a specfic font whenever I am provided some
text in random cell i measure the text and insert _ symbol.

for ex.
____________________
My Name is Rahul Gupta
____________________

Please help.

Regards,
Rahul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Measure Text and insert underscore.

Thanks Gary,

Its not an answer to my question, but gave me an idea to solve my query.

Thanks again, but sorry since i am not marking it as ans to the query.

Regards,
Rahul.

"Gary''s Student" wrote:

Here is some demo code that you can modify as needed:

Sub gupta()
Dim s As String
For Each r In Selection
If r.Font.Name = "Arial" Then
s = r.Value
l = Len(s)
If l 2 Then
s = Left(s, 2) & "_" & Right(s, l - 2)
r.Value = s
End If
End If
Next
End Sub

Select a range of cells and run the macro. It looks for cells with the
Arial font and insters an underscore after the second character.
--
Gary's Student


"Rahul Gupta" wrote:

Hello,

I have a requirement that for a specfic font whenever I am provided some
text in random cell i measure the text and insert _ symbol.

for ex.
____________________
My Name is Rahul Gupta
____________________

Please help.

Regards,
Rahul

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Measure Text and insert underscore.

Hello Gary,

I modified the code to look like below, but its giving the error, but i am
not sure why. Can you help?

Sub gupta()
Dim s As String
For Each r In Selection
l = Len(r.Value)
s = Rept("_", l)
r.Offset(-1, 0).Value = s
r.Offset(1, 0).Value = s
Next
End Sub


Regards,
Rahul.

"Rahul Gupta" wrote:

Thanks Gary,

Its not an answer to my question, but gave me an idea to solve my query.

Thanks again, but sorry since i am not marking it as ans to the query.

Regards,
Rahul.

"Gary''s Student" wrote:

Here is some demo code that you can modify as needed:

Sub gupta()
Dim s As String
For Each r In Selection
If r.Font.Name = "Arial" Then
s = r.Value
l = Len(s)
If l 2 Then
s = Left(s, 2) & "_" & Right(s, l - 2)
r.Value = s
End If
End If
Next
End Sub

Select a range of cells and run the macro. It looks for cells with the
Arial font and insters an underscore after the second character.
--
Gary's Student


"Rahul Gupta" wrote:

Hello,

I have a requirement that for a specfic font whenever I am provided some
text in random cell i measure the text and insert _ symbol.

for ex.
____________________
My Name is Rahul Gupta
____________________

Please help.

Regards,
Rahul

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Measure Text and insert underscore.

=rept() is a worksheet function. You can use String() in VBA.

Option Explicit
Sub gupta()
Dim s As String
Dim r As Range
Dim l As Long

For Each r In Selection
l = Len(r.Value)
s = String(l, "_")
r.Offset(-1, 0).Value = s
r.Offset(1, 0).Value = s
Next r
End Sub




Rahul Gupta wrote:

Hello Gary,

I modified the code to look like below, but its giving the error, but i am
not sure why. Can you help?

Sub gupta()
Dim s As String
For Each r In Selection
l = Len(r.Value)
s = Rept("_", l)
r.Offset(-1, 0).Value = s
r.Offset(1, 0).Value = s
Next
End Sub

Regards,
Rahul.

"Rahul Gupta" wrote:

Thanks Gary,

Its not an answer to my question, but gave me an idea to solve my query.

Thanks again, but sorry since i am not marking it as ans to the query.

Regards,
Rahul.

"Gary''s Student" wrote:

Here is some demo code that you can modify as needed:

Sub gupta()
Dim s As String
For Each r In Selection
If r.Font.Name = "Arial" Then
s = r.Value
l = Len(s)
If l 2 Then
s = Left(s, 2) & "_" & Right(s, l - 2)
r.Value = s
End If
End If
Next
End Sub

Select a range of cells and run the macro. It looks for cells with the
Arial font and insters an underscore after the second character.
--
Gary's Student


"Rahul Gupta" wrote:

Hello,

I have a requirement that for a specfic font whenever I am provided some
text in random cell i measure the text and insert _ symbol.

for ex.
____________________
My Name is Rahul Gupta
____________________

Please help.

Regards,
Rahul


--

Dave Peterson
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
trim everything from left of first underscore in the text? Mitchell_Collen via OfficeKB.com Excel Worksheet Functions 4 July 28th 09 07:49 PM
underscore in email address covered by hyperlink underscore Chuck Bowser Excel Discussion (Misc queries) 1 April 22nd 09 05:47 PM
Splitting 1 cell into 2 based on underscore in text RJF Excel Worksheet Functions 5 May 9th 06 07:50 PM
Text file to measure file usage ExcelMonkey[_190_] Excel Programming 4 February 4th 05 01:59 PM
Underscore character _ Todd Huttenstine[_2_] Excel Programming 1 November 25th 03 05:08 AM


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