Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Deleting a row

How would I write the code to delete a row depending on if a certain cell is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks Neal.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Deleting a row

Looks like you want to delete ALL the rows that have nothing in column
E. When deleting rows, start from the bottom of the worksheet.

For j=cells(65536,"e").end(xlup).row to 1 step-1
if cells(j,"e")="" then rows(j).delete
next j

This may not be as elegant as some solutions (meaning it might take a
bit longer), but it will work.
James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Deleting a row

That should be

For j=cells(65535,"e").end(xlup).row to 1 step-1
if cells(j,"e")="" then rows(j).delete
next j

Tallo-ho!
James

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Deleting a row

I am assuming that I woould replace "e" with c but what would I replace "j"
with? Can I simplify it by just stating row instead of rows"j".delete?

"Zone" wrote:

That should be

For j=cells(65535,"e").end(xlup).row to 1 step-1
if cells(j,"e")="" then rows(j).delete
next j

Tallo-ho!
James


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Deleting a row

try
Sub RowBeGone()
Columns("c").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
How would I write the code to delete a row depending on if a certain cell
is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks Neal.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Deleting a row

I tried it and nothing happened!

"Don Guillett" wrote:

try
Sub RowBeGone()
Columns("c").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
How would I write the code to delete a row depending on if a certain cell
is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks Neal.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Deleting a row

If Don's code did not work for you, then the empty cells are not truly
"Blank". They may have spaces in them which make them appear to be blank.
Also the column you want to check for blanks is vague because you said "If
e1 is blank delete row 1 and so on." and then your example is
"range("C").Select". And then you ask Zone if you can change his "e" to "c".
This indicates you really want to check column C for blanks. If this is true
then I have some code that may work for you. This code will check column "c"
for blanks. If this is not the right column, then feel free to change "c" to
the correct column letter in my code (3 places). Leave the other letters as
is because they are variables needed to run the code.
Also, if spaces are not the reason your cells appear to be blank then this
code will not do the job either because it will check to see if the cell has
nothing else but spaces, and if it does then delete that row. Give it a try
and let us know.

Sub RowBeGone()
Dim j As Long, x As Long, spce As Long
Dim i As Long, cnt As Long

For j = Cells(65535, "c").End(xlUp).Row To 1 Step -1
x = Len(Cells(j, "c"))
If x = 0 Then
Rows(j).Delete
Else
cnt = 0
For i = 1 To x
spce = InStr(i, Cells(j, "c"), " ", 1)
If spce 0 Then cnt = cnt + 1
Next i
End If
If cnt = x Then Rows(j).Delete
Next j
End Sub

Mike F
"Neal" wrote in message
...
I tried it and nothing happened!

"Don Guillett" wrote:

try
Sub RowBeGone()
Columns("c").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
How would I write the code to delete a row depending on if a certain
cell
is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks
Neal.






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Deleting a row

Don, this will work if there is only one space in the cell. What if there
are two or more. My code, although not as compact as yours, will compare the
number of spaces to the length of the text, and if they are equal, no matter
how many there are, it will delete the row.
Sound reasonable? If the length is 0 then it will immediately delete the row
without testing for spaces.
Mike F
"Don Guillett" wrote in message
...
try this to get spaces and blanks
Sub deleteallblanks()
For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") = " " Or Cells(i, "c") = "" Then Rows(i).Delete
Next i
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
I tried it and nothing happened!

"Don Guillett" wrote:

try
Sub RowBeGone()
Columns("c").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
How would I write the code to delete a row depending on if a certain
cell
is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks
Neal.







  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Deleting a row

I think OP said "blank" so it's unlikely there would be more than one space.

--
Don Guillett
SalesAid Software

"Mike Fogleman" wrote in message
...
Don, this will work if there is only one space in the cell. What if there
are two or more. My code, although not as compact as yours, will compare
the number of spaces to the length of the text, and if they are equal, no
matter how many there are, it will delete the row.
Sound reasonable? If the length is 0 then it will immediately delete the
row without testing for spaces.
Mike F
"Don Guillett" wrote in message
...
try this to get spaces and blanks
Sub deleteallblanks()
For i = Cells(Rows.Count, "c").End(xlUp).Row To 2 Step -1
If Cells(i, "c") = " " Or Cells(i, "c") = "" Then Rows(i).Delete
Next i
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
I tried it and nothing happened!

"Don Guillett" wrote:

try
Sub RowBeGone()
Columns("c").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Don Guillett
SalesAid Software

"Neal" wrote in message
...
How would I write the code to delete a row depending on if a certain
cell
is
blank?
If e1 is blank delete row 1 and so on.

range("C").Select
do
row.Delete Shift:=xlUp
loop until isempty(activecell<" ")

Or something like this? I would greatly appreciate the help. Thanks
Neal.











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
Deleting the text without deleting the formula gems04 Excel Worksheet Functions 3 January 30th 09 11:21 PM
Deleting cell data without deleting formula Tom Hall Excel Discussion (Misc queries) 4 October 29th 06 04:07 PM
deleting values in a worksheet without deleting the formulas patti Excel Worksheet Functions 1 October 28th 05 09:49 PM
how prevent formula in cell from deleting when deleting value???? sh-boom New Users to Excel 1 September 30th 05 06:12 PM
Deleting Hyphens or Dashes from multiple cells without deleting the remaining content rmaloy Excel Programming 5 February 9th 04 01:59 AM


All times are GMT +1. The time now is 07:35 PM.

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

About Us

"It's about Microsoft Excel"