Checking for blank rows in database - with apologies to Norman Jon

P

Peter Rooney

Good morning all!
The reason for the apology to Norman is I started a different thread
yesterday where he was helping me, but I can't find it at work this morning,
so I hope he doesn't think I'm being rude!

I'm working with a database that occupies columns B:L and I'm trying to
prevent users from having a row where Bx:Lx contains all blank cells, as I
use currentregion to add and delete rows, and it doesn;t work properly if it
encounters a blank row.

This is what I tried in my Worksheet_Change macro (which works in all other
respects). I'm attempting a multiple IF statement to check each cell in the
current row from column B to column L. If all cells are empty, a value is
entered into column F of the current row.

The problem is that although no error messages are displayed re: syntax, the
code just doesn't work when I empty all the cells between column B and column
L in the current row. I've tried this in lots of flavours, including IF
len("B" & .row) = 0, but nothing seems to work. I guess it's something do do
with the way in which I'm trying to concatenate the column letter and the
..row of the Target, but I'm now completely stumped.

Can any of you good people out there on a Monday morning give me a hand?

Thanks in advance (and to you too, Norman for helping a sad old man with
nothing better to do on a Sunday afternoon!)

Pete

With Target

'---------------------------------------------------------------------------------
If .Column >= 2 Then
If .Column <= 12 Then
If Application.isblank("B" & .Row) Then
If Application.isblank("C" & .Row) Then
If Application.isblank("D" & .Row) Then
If Application.isblank("E" & .Row) Then
If Application.isblank("F" & .Row) Then
If Application.isblank("G" & .Row) Then
If Application.isblank("H" & .Row) Then
If Application.isblank("I" & .Row) Then
If Application.isblank("J" & .Row) Then
If Application.isblank("K" & .Row) Then
If Application.isblank("L" & .Row) Then
MsgBox ("You CAN'T have blank rows in the
database!")
Range("F" & Target.Row).Formula = "Blank
Eliminator"
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
 
N

Norman Jones

Hi Peter,

Define a name ("MyDatabase") for the database area, and replace the previous
code with:

'======================>>
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim rng2 As Range
Dim rw As Range

Set rng = Range("MyDatabase") '<<===== DEFINE
Set rng2 = Intersect(rng, Target.EntireRow)


If Not rng2 Is Nothing Then
For Each rw In rng2.Rows
If Application.CountA(rw.Cells) = 0 Then
MsgBox ("Database row " & rw.Row _
& " is empty. You CAN'T have " _
& "blank rows in the database!")
End If
Next
End If
End Sub
'<<'======================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top