Loop ignoreing is cell empty check

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

I have a loop which loops through a cell range and first check if it is empty. It should then say if its got text in to do the following if not ignore the following and go to the next cell. But this not happeneing it is still doing the proedures within the loop even if the cell is empty.

Code:
Nrow = 2
For Each cell In Sheets("PPIIIFORM").Range("F4:U644")
    If cell.Value > "" Then Sheets("Input_Reference_Table").Cells(Nrow, 1).Value = cell.Value
    Sheets("Input_Reference_Table").Cells(Nrow, 2).Value = Sheets("PPIIIFORM").Range("A" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 3).Value = Sheets("PPIIIFORM").Range("B" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 4).Value = Sheets("PPIIIFORM").Range("C" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 5).Value = "True"
    Sheets("Input_Reference_Table").Cells(Nrow, 6).Value = Sheets("PPIIIFORM").Range("D" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 7).Value = Sheets("PPIIIFORM").Range("E" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 8).Value = Sheets("PPIIIFORM").Range("E" & cell.Row).Value & " - " & Sheets("PPIIIFORM").Range(Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", cell.column, 1) & "1").Value
    Sheets("Input_Reference_Table").Cells(Nrow, 11).Value = cell.column - 5
    Sheets("Input_Reference_Table").Cells(Nrow, 12).Value = Not cell.Interior.Color = RGB(217, 217, 217)
    Sheets("Input_Reference_Table").Cells(Nrow, 13).Value = "True"
    Sheets("Input_Reference_Table").Cells(Nrow, 14).Value = cell.Interior.Color = RGB(255, 255, 0)
    Sheets("Input_Reference_Table").Cells(Nrow, 15).Value = Sheets("PPIIIFORM").Range("V" & cell.Row)
    Sheets("Input_Reference_Table").Cells(Nrow, 16).Value = Sheets("PPIIIFORM").Range("W" & cell.Row).Value
    Sheets("Input_Reference_Table").Cells(Nrow, 17).Value = Sheets("PPIIIFORM").Range("X" & cell.Row).Value
    Sheets("Input_Reference_Table").Cells(Nrow, 18).Value = Sheets("PPIIIFORM").Range("Y" & cell.Row).Value
    Sheets("Input_Reference_Table").Cells(Nrow, 19).Value = Sheets("PPIIIFORM").Range("Z" & cell.Row).Value
    Sheets("Input_Reference_Table").Cells(Nrow, 20).Value = Sheets("PPIIIFORM").Range("AA" & cell.Row).Value
    Sheets("Input_Reference_Table").Cells(Nrow, 21).Value = Sheets("PPIIIFORM").Range("AB" & cell.Row).Value
    
    stFormatStyle = cell.NumberFormat
    If Right(stFormatStyle, 1) = "%" Then
         bIsPercentage = True
         stCurrentStyle = "Percent"
         stending = "f%%"
    Else
         bIsPercentage = False
         stCurrentStyle = "Decimal"
         stending = "f%"
    End If
    iPeriodPosition = InStr(stFormatStyle, ".")
    iDecimals = Len(stFormatStyle) - iPeriodPosition
    If bIsPercentage Then iDecimals = iDecimals - 0
    Sheets("Input_Reference_Table").Cells(Nrow, 9).Value = "%10." & iDecimals & stending
    Nrow = Nrow + 1
    Application.StatusBar = cell.Address
Next cell

Does anyone know why its doing this?

Thanks

Jessicaseymour
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I think it should be

Rich (BB code):
If cell.Value <> "" Then Sheets("Input_Reference_Table").Cells(Nrow, 1).Value = cell.Value
 
Upvote 0
Hi,

You have closed the IF block on the same line.

Try this:

Code:
Nrow = 2
For Each cell In Sheets("PPIIIFORM").Range("F4:U644")
    If cell.Value <> "" Then 
       Sheets("Input_Reference_Table").Cells(Nrow, 1).Value = cell.Value
       ..... OTHER STUFF
    End If
Next

Edit: And, as VoG said, you need <> (does not equal).
 
Upvote 0
Hi

Thanks for replying!

Thank you works perfectly!!! Thanks for all your help!!
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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