ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to create a macro to delete multiple rows? (https://www.excelbanter.com/excel-discussion-misc-queries/170934-how-create-macro-delete-multiple-rows.html)

gak27

How to create a macro to delete multiple rows?
 
Greetings!

This question is for Excel 2007.

I am working with data sets that have many rows of data and I only need a
few of them. What I would like to do is create a macro that will delete 100
rows from my worksheet, starting where I place the cursor. What is the best
way to do this? Whenever I try to record the macro and use it I always wind
up having the 100 rows being deleted from the same location, but I need to
move down through the entire spreadsheet.

greg

Chip Pearson

How to create a macro to delete multiple rows?
 
You can delete multiple rows with code like

ActiveCell.Resize(100, 1).EntireRow.Delete

This code will delete entire rows starting with the active cell down to row
number ActiveCell.Row + 99.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"gak27" wrote in message
...
Greetings!

This question is for Excel 2007.

I am working with data sets that have many rows of data and I only need a
few of them. What I would like to do is create a macro that will delete
100
rows from my worksheet, starting where I place the cursor. What is the
best
way to do this? Whenever I try to record the macro and use it I always
wind
up having the 100 rows being deleted from the same location, but I need to
move down through the entire spreadsheet.

greg



Mike H

How to create a macro to delete multiple rows?
 
maybe

Sub addhpb()
ActiveCell.EntireRow.Select
Set MyRange = Selection.Resize(100)
MyRange.Delete
End Sub

Mike

"gak27" wrote:

Greetings!

This question is for Excel 2007.

I am working with data sets that have many rows of data and I only need a
few of them. What I would like to do is create a macro that will delete 100
rows from my worksheet, starting where I place the cursor. What is the best
way to do this? Whenever I try to record the macro and use it I always wind
up having the 100 rows being deleted from the same location, but I need to
move down through the entire spreadsheet.

greg


Gary''s Student

How to create a macro to delete multiple rows?
 
This is a one-liner:

Sub ordinate()
Range(ActiveCell, ActiveCell.Offset(99, 0)).EntireRow.Delete
End Sub

--
Gary''s Student - gsnu200762


"gak27" wrote:

Greetings!

This question is for Excel 2007.

I am working with data sets that have many rows of data and I only need a
few of them. What I would like to do is create a macro that will delete 100
rows from my worksheet, starting where I place the cursor. What is the best
way to do this? Whenever I try to record the macro and use it I always wind
up having the 100 rows being deleted from the same location, but I need to
move down through the entire spreadsheet.

greg


gak27

How to create a macro to delete multiple rows?
 
Thanks! I'll try all of the suggestions. Sorry for the multiple post of
this subject above...

"gak27" wrote:

Greetings!

This question is for Excel 2007.

I am working with data sets that have many rows of data and I only need a
few of them. What I would like to do is create a macro that will delete 100
rows from my worksheet, starting where I place the cursor. What is the best
way to do this? Whenever I try to record the macro and use it I always wind
up having the 100 rows being deleted from the same location, but I need to
move down through the entire spreadsheet.

greg



All times are GMT +1. The time now is 01:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com