ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting blank rows which contain blank drop-down list boxes (https://www.excelbanter.com/excel-programming/424268-deleting-blank-rows-contain-blank-drop-down-list-boxes.html)

al

Deleting blank rows which contain blank drop-down list boxes
 
Is it possible for a macro to do this?

I have seen many macros designed to remove blank rows in Excel but I have
many spreadsheets which, while the trailing rows appear to be blank, some
have list boxes which have not been used (appear blank) and I'd like to
remove those.

Thanks
Al

OssieMac

Deleting blank rows which contain blank drop-down list boxes
 
Hi Al,

Do you mean data validation type drop downs?

If is data validation type drop downs:
"Some have list boxes which have not been used (appear blank)". Do you mean
that no selection has been made or the underlying list is now blank?

What version of xl are you using? Identifying the type of validation was
added to xl2007 so not sure if it could be done in previous versions.

--
Regards,

OssieMac


"Al" wrote:

Is it possible for a macro to do this?

I have seen many macros designed to remove blank rows in Excel but I have
many spreadsheets which, while the trailing rows appear to be blank, some
have list boxes which have not been used (appear blank) and I'd like to
remove those.

Thanks
Al


Tom Hutchins

Deleting blank rows which contain blank drop-down list boxes
 
If you want to delete empty rows which contain one or more cells with
dropdown list data validation in which no selection has been made, this macro
should do it:

Dim Rng As Range

Sub DelEmptyRowsWithDV()
Dim c As Range
Do While CountEmptyCellsWithDV 0
For Each c In Rng
If c.Validation.Type = 3 Then
With ActiveSheet
If Application.CountA(.Rows(c.Row)) = 0 Then
.Rows(c.Row).Delete
End If
End With
End If
Next c
Set Rng = Nothing
Loop
End Sub

Private Function CountEmptyCellsWithDV() As Long
Dim x As Long, m As Range
On Error GoTo CECwDVerr
Set Rng = ActiveCell.SpecialCells(xlCellTypeAllValidation)
x = 0
For Each m In Rng
If Len(m.Value) = 0 And m.Validation.Type = 3 Then
x = x + 1
End If
Next m
CountEmptyCellsWithDV = x
Exit Function
CECwDVerr:
CountEmptyCellsWithDV = -1
End Function

Hope this helps,

Hutch

"Al" wrote:

Is it possible for a macro to do this?

I have seen many macros designed to remove blank rows in Excel but I have
many spreadsheets which, while the trailing rows appear to be blank, some
have list boxes which have not been used (appear blank) and I'd like to
remove those.

Thanks
Al


al

Deleting blank rows which contain blank drop-down list boxes
 
Tom you are a true master of Excel VBA - thank-you very very much
This is exactly what I needed.
Al

"Tom Hutchins" wrote:

If you want to delete empty rows which contain one or more cells with
dropdown list data validation in which no selection has been made, this macro
should do it:

Dim Rng As Range

Sub DelEmptyRowsWithDV()
Dim c As Range
Do While CountEmptyCellsWithDV 0
For Each c In Rng
If c.Validation.Type = 3 Then
With ActiveSheet
If Application.CountA(.Rows(c.Row)) = 0 Then
.Rows(c.Row).Delete
End If
End With
End If
Next c
Set Rng = Nothing
Loop
End Sub

Private Function CountEmptyCellsWithDV() As Long
Dim x As Long, m As Range
On Error GoTo CECwDVerr
Set Rng = ActiveCell.SpecialCells(xlCellTypeAllValidation)
x = 0
For Each m In Rng
If Len(m.Value) = 0 And m.Validation.Type = 3 Then
x = x + 1
End If
Next m
CountEmptyCellsWithDV = x
Exit Function
CECwDVerr:
CountEmptyCellsWithDV = -1
End Function

Hope this helps,

Hutch

"Al" wrote:

Is it possible for a macro to do this?

I have seen many macros designed to remove blank rows in Excel but I have
many spreadsheets which, while the trailing rows appear to be blank, some
have list boxes which have not been used (appear blank) and I'd like to
remove those.

Thanks
Al



All times are GMT +1. The time now is 03:46 AM.

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