PDA

View Full Version : If..Then for Empty Column



aabnormal
09-22-2008, 11:47 AM
Hello All!
Once again I could use a little assistance. I am looking to run a sorting sub that I have listed as a public sub (Copy_Confirms) if the column is empty. The issue that I am having is that my If..Then statement seems to be incorect as the Copy_Confirms statement is running whether the test is true or false.

I know that determining empty columns can be tricky and so I have tried using IsEmpty, as well as worksheet function CountA > 0 . I have also deleted the entire column, cleared all contents and yet the Copy_Confirms sub is still running when the column is empty. Any idea why?? Thanks in advance.

Sub macro3()
Sheets("Invoice Analysis").Select
If IsEmpty("O1:O65536") = False Then
Copy_Confirms
Else
Selection.Sort Key1:=Range("N1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End If
End Sub

Slyboots
09-22-2008, 01:43 PM
I suggest you use:

Application.WorksheetFunction.CountA(Range("O:O"))

S


Hello All!
Once again I could use a little assistance. I am looking to run a sorting sub that I have listed as a public sub (Copy_Confirms) if the column is empty. The issue that I am having is that my If..Then statement seems to be incorect as the Copy_Confirms statement is running whether the test is true or false.

I know that determining empty columns can be tricky and so I have tried using IsEmpty, as well as worksheet function CountA > 0 . I have also deleted the entire column, cleared all contents and yet the Copy_Confirms sub is still running when the column is empty. Any idea why?? Thanks in advance.

Sub macro3()
Sheets("Invoice Analysis").Select
If IsEmpty("O1:O65536") = False Then
Copy_Confirms
Else
Selection.Sort Key1:=Range("N1"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End If
End Sub

david000
09-22-2008, 11:02 PM
Sub macro3()
Dim x As Integer
x = Application.WorksheetFunction.CountA(Intersect(ActiveSheet.Columns(15), ActiveSheet.UsedRange))
If x = 0 Then
MsgBox "empty"
Else
MsgBox "not empty"
End If
End Sub