Change Line of code that finds blank cells

Status
Not open for further replies.

ammdumas

Active Member
Joined
Mar 14, 2002
Messages
469
Have an IF statement which which stops an 'add a row' routine if any cell in the first 11 columns are blank (of the row being checked). However, in my haste, one of the columns that it is checking CAN be blank. How do I modify the IF stement to ignore the 7 column out of the 11 it is checking. It's not a simple OR statement. I figured that one out...

If WorksheetFunction.CountA(Range(myrowchk, _
myrowchk.Offset(0, 11))) < 11 Then
MsgBox "Add Data to Columns A through L before adding a " _
& "new row", vbCritical, "Shop Drawing Summary"
Else
'add a row rountine
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
ammdumas,

Do you mean that you have to check 11 - 7 = 4 cells to be blank ?

this example is checking columns 3, 5, 6 and 8
Code:
Sub test()
rtc = 1
If WorksheetFunction.CountA(Cells(rtc, 3), Cells(rtc, 5), Cells(rtc, 6), Cells(rtc, 8)) < 4 Then
MsgBox "Add Data to Columns A through L before adding a " _
& "new row", vbCritical, "Shop Drawing Summary"
Else
End If
End Sub

kind regards,
Erik
 
Upvote 0
No.

Originally it was "Stop routine if any cells in columns 1 through 11 are blank". I actually got this code from Von Pookie and it works great...until I found out that it has to ignore the 7th column (cells in 7th column CAN be blank). I think her code uses COUNTA and inconjunction, specifies the number of columns to check (i.e. 11) so that

If WorksheetFunction.CountA(Range(myrowchk, myrowchk.Offset(0, 11))) < 11 Then

basically says in the line I'm checking, if anything less than all 11 column are 'not blank', then stop.

Because I have to ignore column seven, this function becomes too simplistic.

I think I read that right.
 
Upvote 0
to be sure:
A to L are 12 columns
so when column 7 is not to be checked indeed there have to be 11 arguments

If WorksheetFunction.CountA(Range("A" & rtc & ":F" & rtc), Range("H" & rtc & ":L" & rtc)) < 11 Then

will this do what you want ?
kind regards,
Erik
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,203,566
Messages
6,056,110
Members
444,846
Latest member
pbailey

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top