+ Reply to Thread
Results 1 to 10 of 10

Delete rows based on fill color

  1. #1
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52

    Delete rows based on fill color

    hi,

    i found a link to my problem in the subject title below,

    http://www.ozgrid.com/forum/showthre...t=45580&page=2

    The guy at the end of the post says he got it working in the end, but no one seems to have posted the final solution - could someone tell me if the solution is actually in the thread, and if so where!

    My problem is outlined by this guy - basically i want to be able to delete rows in a range that have no fill color, and so keep the ones that are colored.

    thanks

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, In simple terms this should do what you want.
    Please Login or Register  to view this content.
    Regards Mick

  3. #3
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52
    hi ,

    thanks for your response - i inserted a module into the workbook and put the code in.

    How do i use it though? I can't see a way of using it from looking at the code.

    Sorry for being a noob.

  4. #4
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, Have a read of this , it should help !

    Inserting a Command Button in worksheet and Allocating Code

    Open your workbook at the Sheet Number with your Data that you want to Manipulate.
    Click View, Toolbars, Control ToolBox,---- Control ToolBox Menu Appears on sheet.
    Slide you cursor over the Tool Box (Tool Tip Text) until you find a Command Button.
    Click It then click Somewhere on the sheet.-- Command Button appears on sheet.
    The Command Button will have handles round its edge, This is so you can Position it on the sheet.
    Click the command Button "Hold the Mouse Click Down" and Drag the Command Button to where you want it.
    Double Click the Command Button, The VB Editor window will appear.
    You can also open the Editor By clicking Alt + F11, but if you double click the Command Button the editor will open in the procedure relating specifically to your Command Button.
    If the VB Editor window has two panes the right pane is where you must paste your code.
    The left pane can be "Project Window" or "Properties Window, Click (Ctrl+R) if not showing.

    Paste your code just under the words "Private Sub CommandButton1_Click() " in the Right hand pane.
    If you have done this correctly. Scroll to the bottom of the code and you should see the words "End Sub"
    On the VB Window, Toolbar you will see a Green Triangular shapes icon,.
    This is to change the VB Editor mode from "Run Mode" to "Design Mode "
    Click this Icon, The Small blue square to its left will change from light blue to dark blue, or Vice Versa. Before you close the Editor make sure this Square is "Dark Blue" i.e. (Reset)
    Sometimes the it will appear Reset when it is not, that why I usually put a message at the bottom of the code, to know if is run or not.(You do not have a msgbox in your code)
    Close the Editor. Select the Command Button and Click it.
    When the code Runs the Msgbox should appear With The Message "Transfer Complete" ,if this doesn't happen Open The VB Editor "Alt + F11" and click the "Reset ( Blue Square) and or The "Green Triangle" on the Tool bar . The Blue Square should be "Dark Blue ", in order to run the code..
    NB:- If you want to get back into this specific code through the Command Button.
    Get the Controls ToolBox menu back on the screen, Click the green triangle, When you slide the cursor over your Command button , The cursor shape will change to a "Arrow Headed Cross" , you will then be able to double click it to view your code.
    If you prefer, you can forgo all this hassle by putting the code in an MT macro, with a key combination like (Ctrl+"A") to run it.
    If you still get a problem , call back
    Regards Mick

  5. #5
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52
    hi mick,

    certainly learning something new today!

    i created the command button, followed the instructions, ran it, but it still didn't seem to do anything.
    i've attached the file i was testing it on.
    as you can see i just made some rows up to column H, with some that are red, and ones with no fill, in the hope that when i pressed the button, rows 4,5, and 9 would dissapear.

    im obviously doing something completely wrong, would appreciate your input on it.

    cheers.
    Attached Files Attached Files

  6. #6
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    Hi schueyisking,

    That code would work if the cells in column A had data in them. The reason it doesn't work is that the line

    Please Login or Register  to view this content.
    ends up as being 1 because that line is looking for data in Column A.

    If, however, you selected all the cells you need in Column A and then run this code it should do what you want:

    Please Login or Register  to view this content.
    Last edited by SOS; 08-21-2008 at 12:32 PM.
    Hope this helps

    Seamus

  7. #7
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi, The reason it's not working is because you have no Data in column "A".
    If you want it to work that way change the Variable "Last" to a row number like this:-
    Last = 50 (Or Whatever)
    NB I've just seen you already got the solution fron SOS!!
    Regards Mick

  8. #8
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52
    Oooooh right I see.

    Yeh I would actually be using this on rows with data, so the original code will work then, sorry I didn't realise it was dependent on looking for information in the cells (I can't read code at all obviously).

    Thanks, i'll give it a go now, should work.

    much appreciated.

  9. #9
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52
    awesome it works fine now,the original code.

    thank you!

  10. #10
    Registered User
    Join Date
    07-30-2008
    Location
    UK
    Posts
    52
    Actually i've discovered a problem,

    The code works with cells highlighted with a fill colour, but unfortunately doesn't work for cells which have a color due to a conditional format. Is there any way to modify the code so that it detects the conditionally formatted colour, and deletes that row instead?

    Or if thats not possible, a button, that when pressed, automatically converts the conditionally formatted color to a fill color of the same color, if that makes sense. So if the cell is Red, due to a conditional format, a button is pressed, and it removes the conditional formatting but keeps the color as red - Then i could use the code as normal.

    Just this final problem to solve then my spreadsheet is complete!
    Please help!
    Last edited by schueyisking; 08-22-2008 at 05:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. macro: changing cell color based on count in cell
    By Vbort44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2008, 07:28 PM
  2. create a simple macro that changes fill color
    By Niclas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2008, 05:13 PM
  3. Delete rows based on values from worksheet
    By dc6463 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-29-2008, 10:16 AM
  4. color fill rows?
    By tgs23lax in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2007, 03:08 PM
  5. Replies: 2
    Last Post: 03-01-2007, 04:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1