+ Reply to Thread
Results 1 to 8 of 8

Remove part of string

  1. #1
    Registered User
    Join Date
    09-26-2007
    Posts
    9

    Remove part of string

    I have a column as such:
    123/456
    RENT/214
    789/456
    123/989

    What I need to do is, look at the text before the "/" and replace the whole string with another string (based on the pre-defined value).

    I have created a loop to loop through the rows in the a single column and replace a specific value:
    Please Login or Register  to view this content.
    I haven't figured out how to strip part of the word. Any help would be appreciated.
    Last edited by Desi_bhai; 09-27-2007 at 01:10 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Can you explain in plain English what you are trying to do and exactly how your data are set out?

  3. #3
    Registered User
    Join Date
    09-26-2007
    Posts
    9
    I am trying to remove anything after the "/" in a string, then replace that string with another string, which will be hard-coded.
    So, if original data is:
    123/567
    and hard coded in the code is that 123 should be replaced by "John".
    the above line should become John.

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See if this gives you any ideas

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Registered User
    Join Date
    09-26-2007
    Posts
    9
    This helps, but what exactly does the >1 mean?

    Quote Originally Posted by VBA Noob
    See if this gives you any ideas

    Please Login or Register  to view this content.
    VBA Noob

  6. #6
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    for testing I am assuming your range is B1:b10, then the code is

    Private Sub CommandButton1_Click()
    For Each ce In Range("b1:b10")
    If InStr(ce.Value, "/") <> 0 Then
    Select Case Left(ce.Value, InStr(ce.Value, "/") - 1)
    Case "123"
    ce.Value = "john"
    Case "234"
    ce.Value = "smith"
    Case "1234"
    ce.Value = "ashok"
    End Select
    End If
    Next
    End Sub
    I have hardcoded 123>john, 234>smith,1234>ashok. you can add as many and change as many as you want.

    A V Veerkar

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    I added

    Please Login or Register  to view this content.
    to check if cell contains a
    /
    VBA Noob

  8. #8
    Registered User
    Join Date
    09-26-2007
    Posts
    9
    Thank you A V Veerkar, that is exactly what I wanted.

    Quote Originally Posted by avveerkar
    for testing I am assuming your range is B1:b10, then the code is



    I have hardcoded 123>john, 234>smith,1234>ashok. you can add as many and change as many as you want.

    A V Veerkar

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1