ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting rows with no value in column A (https://www.excelbanter.com/excel-programming/330578-re-deleting-rows-no-value-column.html)

filo666

Deleting rows with no value in column A
 
sub DeleteUnusedRows()
dim row as integer
row=1
while row<10000
if cells(a,1)="" then
rows(a).delete
end if
wend
end sub
' put attention in: while row<10000 the 10000 number is the maximum number
'of rows in your sheet. change it if you have a bigger number of rows


HTH

"scratching my head" wrote:

I have several spreadsheets in which 4 of every 5 Rows needs to be deleted.
ie: Row
1 is good, Row 6 is good, Row 11 is good, Row 16 is good, etc. I need to
delete Rows 2-5, 7-10, 12-15, etc. I would prefer to set a variable in the
macro to tell it how many sets of 4 consecutive rows I need deleted (with one
good row between each bad set of 4). The rows that need to be deleted are not
entirely blank, some of the cells have data (not needed) but there are a few
rows that are entirely blank. It needs to delete the rows irreguardless of
any data in that row. Help is appreciated as I am not a programmer but you
guys are really good.

OR

Every 5th cell in column A has data. I need to delete all ROWS that have no
data in COLUMN A(even if it is a "space" that was used to delete previous
data) in column A. How would it know when it reached the end of the data and
continue to delete the balance of the blank spreadsheet?

Thanks
Danny



scratching my head

Deleting rows with no value in column A
 
When I attempt to run the code below, I get an error "if Cells(a,1)="" then"
that says there is a "application-defined or object-defined error".

What do I do?
Thanks for the help.
Danny

"filo666" wrote:

sub DeleteUnusedRows()
dim row as integer
row=1
while row<10000
if cells(a,1)="" then
rows(a).delete
end if
wend
end sub
' put attention in: while row<10000 the 10000 number is the maximum number
'of rows in your sheet. change it if you have a bigger number of rows


HTH

"scratching my head" wrote:

I have several spreadsheets in which 4 of every 5 Rows needs to be deleted.
ie: Row
1 is good, Row 6 is good, Row 11 is good, Row 16 is good, etc. I need to
delete Rows 2-5, 7-10, 12-15, etc. I would prefer to set a variable in the
macro to tell it how many sets of 4 consecutive rows I need deleted (with one
good row between each bad set of 4). The rows that need to be deleted are not
entirely blank, some of the cells have data (not needed) but there are a few
rows that are entirely blank. It needs to delete the rows irreguardless of
any data in that row. Help is appreciated as I am not a programmer but you
guys are really good.

OR

Every 5th cell in column A has data. I need to delete all ROWS that have no
data in COLUMN A(even if it is a "space" that was used to delete previous
data) in column A. How would it know when it reached the end of the data and
continue to delete the balance of the blank spreadsheet?

Thanks
Danny



filo666

Deleting rows with no value in column A
 
Sorry, copy this code

Sub DeleteUnusedRows()
Dim row As Integer
row = 1
While row < 1000
If Cells(row, 1) = "" Then
Rows(row).Delete
End If
row = row + 1
Wend
End Sub

Please tell me if it works fine¡¡¡

"scratching my head" wrote:

When I attempt to run the code below, I get an error "if Cells(a,1)="" then"
that says there is a "application-defined or object-defined error".

What do I do?
Thanks for the help.
Danny

"filo666" wrote:

sub DeleteUnusedRows()
dim row as integer
row=1
while row<10000
if cells(a,1)="" then
rows(a).delete
end if
wend
end sub
' put attention in: while row<10000 the 10000 number is the maximum number
'of rows in your sheet. change it if you have a bigger number of rows


HTH

"scratching my head" wrote:

I have several spreadsheets in which 4 of every 5 Rows needs to be deleted.
ie: Row
1 is good, Row 6 is good, Row 11 is good, Row 16 is good, etc. I need to
delete Rows 2-5, 7-10, 12-15, etc. I would prefer to set a variable in the
macro to tell it how many sets of 4 consecutive rows I need deleted (with one
good row between each bad set of 4). The rows that need to be deleted are not
entirely blank, some of the cells have data (not needed) but there are a few
rows that are entirely blank. It needs to delete the rows irreguardless of
any data in that row. Help is appreciated as I am not a programmer but you
guys are really good.

OR

Every 5th cell in column A has data. I need to delete all ROWS that have no
data in COLUMN A(even if it is a "space" that was used to delete previous
data) in column A. How would it know when it reached the end of the data and
continue to delete the balance of the blank spreadsheet?

Thanks
Danny




All times are GMT +1. The time now is 09:02 AM.

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