LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
CB CB is offline
external usenet poster
 
Posts: 97
Default Eliminating commas if they are first characters in a string

I have written a bit of code to delete a comma if it happens to be the first
character in a string, however my code seems to be deleting all commas, I am
a VB beginner can anyone help me out?

What I thought my code did:
If have ",,Hello, my, name,,, is" in a cell before I run the code, after I
run the code I would like the cell to look like "Hello, my, name,,, is"


What my code seems to do:
Output: "Hello my name is"

This is my code (I have pieced it together from looking at the forum so I
may not fully understand what is going on):

Sub ahhhhhhhh()

For Each cell In Range("H59:H60")
If InStr(1, cell.Value, ",", vbTextCompare) = 1 Then
cell.Value = Replace(cell.Value, ",", "", 1, -1, vbTextCompare)
End If
Next

End Sub

 
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
count no. of commas (,) in a string in a cell hsg Excel Worksheet Functions 3 March 24th 09 06:51 PM
String separated with commas Jarle Excel Programming 5 February 28th 08 12:41 AM
eliminating text between two specific characters Garbunkel[_2_] Excel Programming 5 October 23rd 06 03:32 PM
How can I break down a string with data divided by commas WannaBeExceller Excel Programming 1 January 30th 06 11:34 PM
removing commas from a string TheIrishThug[_3_] Excel Programming 4 December 18th 05 05:50 PM


All times are GMT +1. The time now is 11:52 PM.

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"