View Single Post
 
Old 11-14-2011, 04:58 AM
Hwyn Hwyn is offline Windows Vista Office 2007
Novice
 
Join Date: Nov 2011
Location: Cardiff
Posts: 5
Hwyn is on a distinguished road
Default Vba, Is there a better way to test empty cells?

Hello everyone, I have some working Excel 2007 code, but i was wondering if there is a shorter way of testing consecutive cells in a row to see if they are empty rather than testing each cell individually, typically columns "J" to "Q" .This is my first post, apologies if i haven't structured my question properly.

Sub
Dim rng As Range, cell As Range
LastRow = Cells(Rows.Count, "a").End(xlUp).Row
Set rng = Range("a2:a" & LastRow)
For Each cell In rng
If cell.Value Like "*FUJ*" And _
IsEmpty(Cells(cell.Row, "j")) And IsEmpty(Cells(cell.Row, "k")) And _
IsEmpty(Cells(cell.Row, "l")) And IsEmpty(Cells(cell.Row, "m")) And _
IsEmpty(Cells(cell.Row, "n")) And IsEmpty(Cells(cell.Row, "o")) And _
IsEmpty(Cells(cell.Row, "p")) And IsEmpty(Cells(cell.Row, "q")) = True Then
Cells(cell.Row, "u").Value = "Out of Stock"
Else
Cells(cell.Row, "u").Value = "In Stock"
End If
Next
End Sub

Regards Robert
Reply With Quote