PC Review


Reply
Thread Tools Rate Thread

To delete specific color index row

 
 
=?Utf-8?B?SnVuaW9yNzI4?=
Guest
Posts: n/a
 
      6th Jun 2007
Hi,

I tried to run the macro code below, but it does not even run when i
execute. Not sure if i have typed the code correctly??? Can someone advise?

Sub Testing()

ActiveSheet.Activate
Range("A1").Select


For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row

If Rows(i).Interior.ColorIndex = 6 Then
Rows(LastRow).Select
Selection.Delete

i = i + 1
End If

Next i

End Sub



 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      6th Jun 2007
Hi Junior,

You should try to avoid selections as these are usually
unnecessary and inefficient.Additionally, it is advisable
always to declare all variables explicitly.

Perhaps, however, you could explain what the variable
LastRow is intended to refer to and exactlty what the
procedure is intended to do


---
Regards,
Norman


"Junior728" <(E-Mail Removed)> wrote in message
news:F0C69CD5-A4FE-4404-A7E4-(E-Mail Removed)...
> Hi,
>
> I tried to run the macro code below, but it does not even run when i
> execute. Not sure if i have typed the code correctly??? Can someone
> advise?
>
> Sub Testing()
>
> ActiveSheet.Activate
> Range("A1").Select
>
>
> For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
>
> If Rows(i).Interior.ColorIndex = 6 Then
> Rows(LastRow).Select
> Selection.Delete
>
> i = i + 1
> End If
>
> Next i
>
> End Sub
>
>
>



 
Reply With Quote
 
Incidental
Guest
Posts: n/a
 
      6th Jun 2007
Hi

Not sure why your code isn't running and seeing as how your variable
isn't declared in your post its hard to know what you are trying to
do, though I presume from your title and the gist of the code you are
trying to delete all the instances of yellow rows within the used
range in column A? If so the code below should work for you.

As Norman so rightly said it isn't such a great idea to select things
if you don't have to and it is always a good idea to explicitly
declare your variables. Not only for your own use but when it comes
to posting a problem it is easier for people to read.

Add a new module then paste the code below into it.

Option Explicit
Dim MyCell, MyRng As Range
Dim LstCell As Integer

Sub DeleteYellowRows()

With ActiveSheet

LstCell = [A65536].End(xlUp).Row

Set MyRng = Range("A1:A" & LstCell)

For Each MyCell In MyRng

If MyCell.Interior.ColorIndex = 6 Then

MyCell.EntireRow.Delete

End If

Next MyCell

End With

End Sub

You can then call the macro from the macros menu Alt + F8 from the
main excel application window from here you can assign a keyboard
shortcut to the macro from the options button.

Hope this helps

S



 
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
Re: How to create a rule in which all email with a specific subject line causes message to have specific color Roady [MVP] Microsoft Outlook Discussion 0 13th Oct 2009 09:43 PM
Shape color index does not match cell color index Chrisso Microsoft Excel Programming 4 27th Apr 2009 11:47 AM
Chart axes color index vs font color index dennis.benjamin@gmail.com Microsoft Excel Charting 4 7th Dec 2006 04:05 PM
Setting Background Color RGB (Always goes to closest index color) ryanmhuc@yahoo.com Microsoft Excel Programming 6 2nd Dec 2005 11:47 PM
how to auto delete all index entries entered by an index file mason Microsoft Word Document Management 1 13th Feb 2004 02:42 AM


Features
 

Advertising
 

Newsgroups
 


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