Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / October 2008

Tip: Looking for answers? Try searching our database.

deleting characters from autofiltered cells.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bert - 12 Oct 2008 13:46 GMT
I'm using the following subroutine to look at a specific autofiltered
cell, and if there are caret characters in it, to make the text in
between italic.  Then it is supposed to delete the carets (^).  It (or
a variation of it) worked in non-autofiltered cells.  Here, the
italics line works, but the delete line causes a 1004 error.  Here's
the code: ("C" is the specific cell)

Sub MakeItalic(C As Object)
Dim D1 As Integer
Dim D2 As Integer
Dim rng As Range
Set rng = Worksheets("Student_Data").AutoFilter.Range
rw1 = C.Row
clm1 = C.Column
Do While InStr(1, C.Text, "^")
    D1 = Int(InStr(1, C.Text, "^"))
    D2 = Int(InStr(D1 + 1, C.Text, "^"))
    rng.Characters(Start:=D1 + 1, Length:=(D2 - 1) -
D1).Font.FontStyle = "Italic"
    rng.Cells(rw1, clm1).Characters(Start:=D2, Length:=1).Delete
    Worksheets("Student_Data").Cells(rw1, clm1).Characters(Start:=D1,
Length:=1).Delete
Loop
End Sub
Per Jessen - 12 Oct 2008 14:48 GMT
Hi
As your range is already autofitered, I don't see why you want to use the
autofilter statement again.

Try if this will do it:

Sub MakeItalic(ByVal C As Range)
Dim D1 As Long
Dim D2 As Long
Set C = C.Cells(1, 1)
Do While InStr(1, C.Text, "^")
   D1 = InStr(1, C.Text, "^")
   D2 = InStr(D1 + 1, C.Text, "^")
   C.Characters(Start:=D1 + 1, Length:=(D2 - 1) - D1).Font.FontStyle =
"Italic"
   C = Application.WorksheetFunction.Substitute(C.Value, "^", "")
Loop
End Sub

BTW: I would rather use "C as Range" than "C as Object"

Regards,
Per

> I'm using the following subroutine to look at a specific autofiltered
> cell, and if there are caret characters in it, to make the text in
[quoted text clipped - 20 lines]
> Loop
> End Sub
bert - 12 Oct 2008 15:46 GMT
Per:
Thanks.  This is almost doing it.  Your last line: C =
Application.WorksheetFunction.Substitute(C.Value, "^", "")
does delete the ^'s but it also changes the italicized text back to
normal text.
If there's a way around that.
Bert

> Hi
> As your range is already autofitered, I don't see why you want to use the
[quoted text clipped - 46 lines]
>
> - Show quoted text -
bert - 12 Oct 2008 15:58 GMT
Per:
Disregard my other message.  I combined my approach with yours, and it
works fine, deleting the ^'s and preserving the italics:
   C.Characters(Start:=D2, Length:=1).Delete
   C.Characters(Start:=D1, Length:=1).Delete
Thanks so much.
Bert

> Hi
> As your range is already autofitered, I don't see why you want to use the
[quoted text clipped - 46 lines]
>
> - Show quoted text -
Per Jessen - 12 Oct 2008 17:50 GMT
Hi Bert

Thanks for your reply, I'm glad to help.

--
Per

Per:
Disregard my other message.  I combined my approach with yours, and it
works fine, deleting the ^'s and preserving the italics:
   C.Characters(Start:=D2, Length:=1).Delete
   C.Characters(Start:=D1, Length:=1).Delete
Thanks so much.
Bert

On Oct 12, 9:48 am, "Per Jessen" <per.jes...@mail.dk> wrote:
> Hi
> As your range is already autofitered, I don't see why you want to use the
[quoted text clipped - 49 lines]
>
> - Show quoted text -
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.