|
|
Subject:
Simple Macro in Excel to Delete Certain Rows
Category: Computers > Programming Asked by: gotmike-ga List Price: $10.00 |
Posted:
01 Nov 2005 19:44 PST
Expires: 01 Dec 2005 19:44 PST Question ID: 587821 |
|
There is no answer at this time. |
|
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: sithunml-ga on 02 Nov 2005 00:12 PST |
Following procedures that I made is not delete from the original it copy the wanted rows to next sheet. You can edit these to what you want ' this is bold test to make sure the right row that you want to delete Sub boldtest() MsgBox ThisWorkbook.Sheets(1).Rows(1).Font.FontStyle MsgBox ThisWorkbook.Sheets(1).Cells(1, 2).Value End Sub ' this is color test to make sure the right row that you want to delete Sub colortest() MsgBox ThisWorkbook.Sheets(1).Rows(9).Interior.Color MsgBox ThisWorkbook.Sheets(1).Cells(9, 1).Value '65535 is yellow color End Sub ' copy original sheet to new one with removing all unwanted Sub CopyToNewSheet() i = 1 'line count on original sheet x = 1 'line count on new sheet Do Until ThisWorkbook.Sheets(1).Cells(i, 1).Value = "" 'checking the end of rows If ThisWorkbook.Sheets(1).Rows(i).Interior.Color <> 65535 Then ' you can change here yellow or bold ThisWorkbook.Sheets(2).Rows(x).Value = ThisWorkbook.Sheets(1).Rows(i).Value x = x + 1 'move to next new line End If i = i + 1 'move to next line Loop MsgBox "done! All records " & x & " copy to sheet2" End Sub This is not answer just comment |
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: gotmike-ga on 02 Nov 2005 10:06 PST |
Thanks for the great response. With some tweaking I was able to get the color based macro to work, but it only copies rows that are highlighted in yellow in their entirety. If you could submit your script as an answer with some minor changes to copy over rows that have any cell highlighted I would gladly accept it. In my spreadsheet only certain cells are highlighted, and I need to copy over any rows that have one or more highlighted cells in them. Thanks in advance. --Mike |
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: sithunml-ga on 02 Nov 2005 18:40 PST |
I'm very glad to here that I submitted script is usefull/reference to you, You can use this script under GNU :D Just Kidding I'll not submit as an answer, actually I'm not vb guy and no good at english too. sithu |
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: gotmike-ga on 02 Nov 2005 19:36 PST |
Could you help with the problem I am having regarding copying rows that only have one or more cells highlighted. The script that you wrote is great, but it only works if the whole row is highlighted in yellow. I need it to copy rows that have only one (or a few) cells highlighted in yellow. Thanks so much for your help. Your english seems pretty good to me :) --Mike |
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: sithunml-ga on 03 Nov 2005 18:59 PST |
This following procedure and function can fullfill your requirement you only need to run CopyToNewSheet procedure it will call the function CheckColorInRow to check the color exit in each row Sub CopyToNewSheet() i = 1 'line count on original sheet x = 1 'line count on new sheet Do Until ThisWorkbook.Sheets(1).Cells(i, 1).Value = "" 'checking the end of rows If CheckColorInRow(i) = True Then ' check current row have colored field ThisWorkbook.Sheets(2).Rows(x).Value = ThisWorkbook.Sheets(1).Rows(i).Value x = x + 1 'move to next new line in new sheet End If i = i + 1 'move to next line in original sheet Loop MsgBox "done! All records " & x & " copy to sheet2" End Sub Function CheckColorInRow(RowsNo) As Boolean y = 1 ' column count Do Until ThisWorkbook.Sheets(1).Cells(RowsNo, y).Value = "" If ThisWorkbook.Sheets(1).Cells(RowsNo, y).Interior.Color <> 16777215 Then ' checking the uncolored cell CheckColorInRow = True Exit Function End If y = y + 1 Loop CheckColorInRow = False End Function |
Subject:
Re: Simple Macro in Excel to Delete Certain Rows
From: sithunml-ga on 03 Nov 2005 19:07 PST |
If your row have two or more colored cells and you only need is yellow then change the color number in this line according to your requirement For eg. If ThisWorkbook.Sheets(1).Cells(RowsNo, y).Interior.Color <> 16777215 Then to If ThisWorkbook.Sheets(1).Cells(RowsNo, y).Interior.Color = 65535 Then |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |