Consulting

Results 1 to 7 of 7

Thread: Delete Characters in a string

  1. #1
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    4
    Location

    Delete Characters in a string

    Hello Team,

    I am facing a similar problem as discussed in this thread . The error for me occurs at

    Code
    xlWB.Worksheets("Consistency_Check").Range("F" & colnum1).Characters(Start:=264, Length:=5).Text = ""

    colnum1 = 17

    I wish to delete the characters at this position.

    Best Regards,
    Umesh
    Last edited by Bob Phillips; 09-01-2014 at 03:04 AM. Reason: Moved to own thread

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You need to build a new string with the characters you wish to keep.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    4
    Location
    It did work for other ranges, but this particular range seem to throw the error. I tried the new string but it looses the formatting of the content.
    Last edited by UmeshM; 09-01-2014 at 04:00 AM.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So it does. I have never tried that but it surprised me.

    What error are you getting, is the sheet name spelled correctly.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    4
    Location
    When I run the code though Word VBA it throws the Run time Error 1004

    Adding test file along with this reply

    I tried running this code in this excel
    Worksheets("Sheet1").Range("A1").Characters(Start:=277, Length:=5).Text = ""

    Result and Findings
    Above code does not work on any content whose length is more than 250
    Attached Files Attached Files

  6. #6
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    4
    Location
    Can I delete the text without affecting the formatting?

    Quote Originally Posted by UmeshM View Post
    When I run the code though Word VBA it throws the Run time Error 1004

    Adding test file along with this reply

    I tried running this code in this excel
    Worksheets("Sheet1").Range("A1").Characters(Start:=277, Length:=5).Text = ""

    Result and Findings
    Above code does not work on any content whose length is more than 250

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    If you use clear contents it should retain the formatting
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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