ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete characters up to ":" (https://www.excelbanter.com/excel-programming/289900-re-delete-characters-up.html)

Dave Peterson[_3_]

Delete characters up to ":"
 
You can use InStr() to search for the colon and Mid() to ignore the stuff before
it.

Option Explicit
Sub testme()

Dim myStr As String
Dim colonPos As Long

myStr = "this is a test: for removing colons"

colonPos = InStr(1, myStr, ":")
If colonPos 0 Then
myStr = Mid(myStr, colonPos + 1) '+2 to get rid of the linefeed?
End If

MsgBox myStr

End Sub

Robbyn wrote:

I have created a report page that copies comment.txt from the source page (thanks again for help Tom). I'm wondering if it's possible to delete all characters up to and including the ":" on the report page. (This will get rid of the username info).

Robbyn

(Make it stop raining please, ty)


--

Dave Peterson


robbyn

Delete characters up to ":"
 
Ok Dave, playing around with it to see what I get. Thanks for the help. :)

Robbyn

robbyn

Delete characters up to ":"
 
Okay Dave. Can't sleep so played around with your code, and it most definitely works when I use activeCell. But the following code doesn't

Sub textme(

Dim myStr As Strin
Dim colonPos As Lon
Dim cell As Rang

For Each cell In Range("a1:a15"
myStr = cell.Valu
colonPos = InStr(1, myStr, ":"
If colonPos 0 The
myStr = Mid(myStr, colonPos + 1
End I
Next cel

End Su

Any idea why? (thanks again

Robbyn

robbyn

Delete characters up to ":"
 
Please disregard post. Figured out my problem. :

Robbyn


All times are GMT +1. The time now is 07:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com