View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen Per Jessen is offline
external usenet poster
 
Posts: 1,533
Default deleting characters from autofiltered cells.

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

"bert" skrev i meddelelsen
...
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