If then statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a piece of code that looks at an Excel spreadsheet, copies the cells
data, and puts it in another Excel sheet.

The first piece of data will always be there. But in some cases, subsequent
fields may be blank. So I want to put in an If statement that says if
subsequent values are blank, just fill them in with the first value. Here is
what I have:

testExpected = .Cells(currentRow, 6).Value
*******
If .Cells.Value is Null then
blah blah
End If
*******
Can someone help me with the code inside the asterisks please.
 
Can you try to use the word 'Empty' instead of 'Null'?
So...

If .Cells.Value = Empty Then
blah
End If
 
I tried this with a worksheet and it identified the empty cells correctly.
This may or may not be what you are looking for. A blank cell can be
identified as an empty string "".

Jeff

Sub JEFF()

Dim ROW As Long
Dim TEMP As String

ROW = 1
Do While ROW < 10
TEMP = ActiveSheet.Cells(ROW, 1).Value
If TEMP = "" Then
Cells(ROW, 2).Value = "BLANK"
Else
Cells(ROW, 2).Value = "NOT BLANK"
End If
ROW = ROW + 1
Loop
End Sub
 
If you dont want to use a loop statement you can use,

ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks).Value = "First
Value"

Now this will put that first value in all blank cells for the entire
used range of the active sheet. If you need to be more specific to a
column or row, just change the first part.
 

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

Back
Top