ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Delete Empty Cells in a Macro (https://www.excelbanter.com/excel-discussion-misc-queries/125298-delete-empty-cells-macro.html)

fak119

Delete Empty Cells in a Macro
 
1) In a range of cells (A1:B119) there are empty lines (e.g. A1:B1) which I
want to delete in a Macro. Is this possible?

2) When I sort a.m. range of cells (A1:B119), containing text, the empty
lines are on top, unless I sort descending. A way out of this other than
manually delete the emtpty cells? Hence question no. 1

Bob Phillips

Delete Empty Cells in a Macro
 


"fak119" wrote in message
...
1) In a range of cells (A1:B119) there are empty lines (e.g. A1:B1) which
I
want to delete in a Macro. Is this possible?



iLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = iLastRow to 1
If Cells(i,"A").Value = "" And Cells(i,"B").Value = "" Then
Rows(i).delete
End If
Next i


2) When I sort a.m. range of cells (A1:B119), containing text, the empty
lines are on top, unless I sort descending. A way out of this other than
manually delete the emtpty cells? Hence question no. 1




fak119

Delete Empty Cells in a Macro
 
Thank you, Bob, I´m sure this would help.

Unfortunately I am a very poor Macro programmer and I have never done one
like that before (loops, etc.)

Felix

"Bob Phillips" wrote:



"fak119" wrote in message
...
1) In a range of cells (A1:B119) there are empty lines (e.g. A1:B1) which
I
want to delete in a Macro. Is this possible?



iLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = iLastRow to 1
If Cells(i,"A").Value = "" And Cells(i,"B").Value = "" Then
Rows(i).delete
End If
Next i


2) When I sort a.m. range of cells (A1:B119), containing text, the empty
lines are on top, unless I sort descending. A way out of this other than
manually delete the emtpty cells? Hence question no. 1





Bob Phillips

Delete Empty Cells in a Macro
 
Just wrap it in a macro.

First, select the sheet you want to work on. Then go to the VBIDE (Alt-F11),
insert a code module (InsertModule) and paste the code below

Sub ProcessData()
iLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = iLastRow to 1
If Cells(i,"A").Value = "" And Cells(i,"B").Value = "" Then
Rows(i).delete
End If
Next i
End Sub

Go backto Excel (Alt-F11), get the list of macros (Alt-F8), select
Processdata from the list and hit the Run button.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"fak119" wrote in message
...
Thank you, Bob, I´m sure this would help.

Unfortunately I am a very poor Macro programmer and I have never done one
like that before (loops, etc.)

Felix

"Bob Phillips" wrote:



"fak119" wrote in message
...
1) In a range of cells (A1:B119) there are empty lines (e.g. A1:B1)
which
I
want to delete in a Macro. Is this possible?



iLastRow = Cells(Rows.Count,"A").End(xlUp).Row
For i = iLastRow to 1
If Cells(i,"A").Value = "" And Cells(i,"B").Value = "" Then
Rows(i).delete
End If
Next i


2) When I sort a.m. range of cells (A1:B119), containing text, the
empty
lines are on top, unless I sort descending. A way out of this other
than
manually delete the emtpty cells? Hence question no. 1








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

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