Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to delete rows containing specific data Slohcin New Users to Excel 2 December 20th 06 11:52 AM
Macro to delete specific rows Gert-Jan[_2_] Excel Programming 2 December 20th 06 09:29 AM
Macro to keep 15 specific records and delete 1000 other rows. Sam Excel Programming 6 October 23rd 06 12:04 AM
Macro to delete specific rows above selected cell [email protected] Excel Programming 3 August 25th 06 04:14 PM
Macro to delete specific rows Steve Excel Programming 12 October 1st 04 11:50 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"