PC Review


Reply
Thread Tools Rate Thread

deleting characters from autofiltered cells.

 
 
bert
Guest
Posts: n/a
 
      12th Oct 2008
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
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      12th Oct 2008
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" <(E-Mail Removed)> skrev i meddelelsen
news:3ad5c5fd-db07-4262-a752-(E-Mail Removed)...
> 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


 
Reply With Quote
 
bert
Guest
Posts: n/a
 
      12th Oct 2008
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

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
> 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" <bwhitt...@verizon.net> skrev i meddelelsennews:3ad5c5fd-db07-4262-a752-(E-Mail Removed)...
>
>
>
> > 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- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
bert
Guest
Posts: n/a
 
      12th Oct 2008
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
> 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" <bwhitt...@verizon.net> skrev i meddelelsennews:3ad5c5fd-db07-4262-a752-(E-Mail Removed)...
>
>
>
> > 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- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      12th Oct 2008
Hi Bert

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

--
Per

"bert" <(E-Mail Removed)> skrev i meddelelsen
news:debc3962-f868-4436-af9b-(E-Mail Removed)...
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
> 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" <bwhitt...@verizon.net> skrev i
> meddelelsennews:3ad5c5fd-db07-4262-a752-(E-Mail Removed)...
>
>
>
> > 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- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting characters in a column of cells -converting to text strin Chris Maddogz Microsoft Excel Programming 2 15th Jun 2009 04:10 AM
Deleting LF Characters in cells BillH Microsoft Excel Worksheet Functions 9 19th Mar 2008 10:19 PM
Deleting characters from cells in access =?Utf-8?B?Q0MgU2FudGEgTW9uaWNh?= Microsoft Access Queries 7 27th Oct 2006 05:10 PM
autofiltered cells =?Utf-8?B?bWlub3N0cmFkYQ==?= Microsoft Excel Programming 1 7th Nov 2005 01:51 PM
Deleting AutoFiltered Rows Nirmal Singh Microsoft Excel Programming 11 7th Feb 2005 06:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.