I'm pretty new to VBA
I have a problem where I need excel to tell me whether there is a blank row or not. The code I am using is:
ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[4]<>0,RC[5]<>0,RC[6]<>0,RC[7]<>0,RC[8]<>0,RC[9]<>0,RC[10]<>0,RC[11]<>0,RC[12]<>0,RC[13]<>0),R2C5,""Blank Row""
"
If one of the cells has data in it I want to keep the row, if not, the next code below deletes the rows that have been flaged as 'blank row' using the above formula
Dim Rng1 As Range
Dim Rng2 As Range
Set Rng1 = Intersect(Selection.Cells(1).EntireColumn, Selection.Parent.UsedRange)
Rng1.Replace "Blank Row", "", xlWhole
On Error Resume Next
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
If Rng2 Is Nothing Then
'nothing to delete
Else
Rng2.EntireRow.Delete
End If
The problem is that the first formula is not flaging the rows that are completely blank. I think this may be a result of the cells containing data validation formulas, but the content are blank.
Has anyone any suggestions.
TIA,
Mark
I have a problem where I need excel to tell me whether there is a blank row or not. The code I am using is:
ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[4]<>0,RC[5]<>0,RC[6]<>0,RC[7]<>0,RC[8]<>0,RC[9]<>0,RC[10]<>0,RC[11]<>0,RC[12]<>0,RC[13]<>0),R2C5,""Blank Row""
If one of the cells has data in it I want to keep the row, if not, the next code below deletes the rows that have been flaged as 'blank row' using the above formula
Dim Rng1 As Range
Dim Rng2 As Range
Set Rng1 = Intersect(Selection.Cells(1).EntireColumn, Selection.Parent.UsedRange)
Rng1.Replace "Blank Row", "", xlWhole
On Error Resume Next
Set Rng2 = Rng1.SpecialCells(xlCellTypeBlanks)
If Rng2 Is Nothing Then
'nothing to delete
Else
Rng2.EntireRow.Delete
End If
The problem is that the first formula is not flaging the rows that are completely blank. I think this may be a result of the cells containing data validation formulas, but the content are blank.
Has anyone any suggestions.
TIA,
Mark