PDA

View Full Version : Delete Characters in a string



UmeshM
09-01-2014, 01:38 AM
Hello Team,

I am facing a similar problem as discussed in this thread (http://www.vbaexpress.com/forum/showthread.php?31277-unable-to-set-the-text-property-of-the-characters-class). 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

Bob Phillips
09-01-2014, 03:05 AM
You need to build a new string with the characters you wish to keep.

UmeshM
09-01-2014, 03:13 AM
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.

Bob Phillips
09-01-2014, 04:20 AM
So it does. I have never tried that but it surprised me.

What error are you getting, is the sheet name spelled correctly.

UmeshM
09-01-2014, 05:25 AM
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

UmeshM
09-02-2014, 12:00 PM
Can I delete the text without affecting the formatting?


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

Aussiebear
09-02-2014, 10:21 PM
If you use clear contents it should retain the formatting