If IsEmpty not returning desired results

tmyers

Well-known member
Local time
Today, 09:50
Joined
Sep 8, 2020
Messages
1,091
I am doing a simple for loop to loop through a range and check if a cell is empty and if it is, copy data in a cell on the row, paste it in another column one on the same row then delete the content in the cell it was copied from.

The loop runs, but never seems to trigger true on the if statement.
Code:
    For X = LastRow To 1 Step -1
        If IsEmpty("G" & X) Then
            Cells(X, 2).Text.Copy
            Cells(X, 4).Paste
            Cells(X, 2).Delete
        End If
    Next X
I have changed to if that cell = null and cell = "" and it still wont trigger. I have gone through and made sure the cells in question were empty as well and no change. What am I missing?
 
you missed Range():

If IsEmpty(Range("G" & X).Value)
 
Excel doesn't really understand Null as potential cell contents, so that won't work.
Try
IsBlank()

1624541664021.png
 
Ah I see. Now it is entering the if statement, but is throwing an object required answer. Hm.
 
there is no IsBlank() in Excel VBA?
 
Changed the method I was using to copy and it is working now.
Switched it to:
Code:
    For X = LastRow To 1 Step -1
        If IsEmpty(Range("G" & X).Value) Then
            Range("B" & X).Copy Range("D" & X)
            Cells(X, 2).Delete
        End If
    Next X
 

Users who are viewing this thread

Back
Top Bottom