Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 2nd, 2003, 12:15 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default move rows to top with cells in columnA filled RED

Hi people

Do you have the VB code that can move the rows to the top with cells background filled in RED color in column (then follow by rows with any cells in column A not being filled in RED color) ?

Alternatively, it will be fine if you have a code that move the rows to the top with any cells in column A that have the font in RED.

Thank for your help in advance.

 
Old December 2nd, 2003, 12:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You'll need something like this
Code:
Private Sub ColorSort()
Dim x As Integer, iInsertedRows As Integer

x = Range("A1").End(xlDown).Row

For x = x To 1 Step -1
    If Cells(x, 1).Interior.ColorIndex = 3 Then '3 is standard red color
        Rows(x).Cut
        Rows("1:1").Insert Shift:=xlDown 'paste the cut row back as row 1
        x = x + 1 'we've just moved everything down a row
        iInsertedRows = iInsertedRows + 1
        If iInsertedRows = x Then Exit For 'we don't need to sort the ones we put there
    End If
Next
End Sub
It's basic, but it works. There's plenty of scope for for customisation ;)

HTH Chris



There are two secrets to success in this world:
1. Never tell everything you know
 
Old December 2nd, 2003, 12:51 PM
Registered User
 
Join Date: Nov 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Chris,

you are fantastic!
Thank you so much!






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move rows in a table bucky483 Javascript How-To 10 March 27th, 2017 12:57 AM
Move Datagrid rows michael29 ASP.NET 1.0 and 1.1 Professional 1 April 24th, 2007 05:31 PM
delete all empty cells and move them to the left crmpicco Excel VBA 1 May 6th, 2005 05:47 AM
Getting the Top 5 Rows from a datatable flyin General .NET 9 June 14th, 2004 08:36 AM
remove rows to Sheet2 (cells in columnA filled RED alienscript Excel VBA 1 December 2nd, 2003 12:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.