Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
Hi All,
I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
Tim, you might be chasing a shadow with the delete and shift method. Excel
only supports the shifting of an entire column or row, not partials. However, you could use the cut and paste methods to move specific ranges. As an example, if you find and empty cell and want to shift all data from right to left. 'Establish right boundry lastCol = Cells(Columns.Count, 1).End(xlToLeft).Column 'insert code to find empty cells and for first empty EmptyCell = CellFound.Address Range(Cells(0, Range(EmptyCell).Offset(0, 1).Col), Cells(0, lastCol).Cut Range(EmptyCell) This would have to be in a loop to execute for each emty cell found. " wrote: Hi All, I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
Tim, disregard the first posting i made. I re-read yours and see that i was
assuming you wanted to find empty cells. Now i see that you want to delete cells with data, without shifting the rows or columns. This can be done by simply setting a range within column A or B or both and using the ClearContents command. The method used for selecting the range to be deleted will depend on whether your data is contiguous, whether you know the exact cell references or whether you have to establish the range based on certain criteria and then offset from key reference points to the end of the range. I can't offer any code for that without knowing how your data is constructed in Columns A and B and if it is consistent throughout all worksheets. " wrote: Hi All, I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
If you only want to delete the cells that contain data in columns A and B then:
Sub delAandBdata() Dim lastRow, dRng lastRow = Cells(Rows.Count, 1).End(xlUp).Row Range("$A$2:$B" & lastRow).ClearContents End Sub The " wrote: Hi All, I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
Thanks man, the "ClearContents" did the trick!
Tim. On Mar 19, 4:31 pm, JLGWhiz wrote: If you only want to delete the cells that contain data in columns A and B then: Sub delAandBdata() Dim lastRow, dRng lastRow = Cells(Rows.Count, 1).End(xlUp).Row Range("$A$2:$B" & lastRow).ClearContents End Sub The " wrote: Hi All, I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim.- Hide quoted text - - Show quoted text - |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro to delete specific rows in different worksheets
Good, glad to help. I was a little slow pulling out the actual requirement.
"Rowlff" wrote: Thanks man, the "ClearContents" did the trick! Tim. On Mar 19, 4:31 pm, JLGWhiz wrote: If you only want to delete the cells that contain data in columns A and B then: Sub delAandBdata() Dim lastRow, dRng lastRow = Cells(Rows.Count, 1).End(xlUp).Row Range("$A$2:$B" & lastRow).ClearContents End Sub The " wrote: Hi All, I've been looking around and have found plenty of examples of how to delete rows of cells with blank entries, delete every nth row, etc, but haven't found anything along the lines of what I'm wishing to do. I have several worksheets, and I'm attempting to create a macro which deletes (but doesn't delete the entire column, thus shifting every other column left one..) a range in these worksheets. I.e. I'm attempting to delete, in a worksheet "Data" every cell which has an entry in it, in columns A and B - the reason for this, is that I have a another column C which stores a formula working off the 2 cells in these columns, and is linked to a different worksheet which will be the "end" product - i.e. presenting the calculated values. Would anyone be able to point me in the right direction? Cheers Tim.- Hide quoted text - - Show quoted text - |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to delete rows containing specific data | New Users to Excel | |||
Macro to delete specific rows | Excel Programming | |||
Macro to keep 15 specific records and delete 1000 other rows. | Excel Programming | |||
Macro to delete specific rows above selected cell | Excel Programming | |||
Macro to delete specific rows | Excel Programming |