If nothing is found move on to next row

keith05281967

Board Regular
Joined
May 6, 2011
Messages
68
Greetings,

The below code loops thru a column of data and adds spacing where needed. But currently if it finds a blank cell it errors out. I need a line of code that says if you find a blank cell then move on to the next row. The code in red doesn't work because it's looking for another "For" but the logic gives the basic idea of what i'm trying to accomplish.


For i = 2 To lastrow
If Cells(i, ColumnnNmber).Value = "" Then
Next i
Else
s = Cells(i, ColumnNumber).Value
s = Trim(s)
s = Left(s, Len(s) - 2) & " " & Right(s, 2)
Cells(i, ColumnNumber).Value = s
Next i


running Excel 2007

thank,
Keith
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Code:
For i = 2 To lastrow
   If Cells(i, ColumnnNmber).Value [COLOR="Red"]<>[/COLOR] "" Then
      s = Cells(i, ColumnNumber).Value
      s = Trim(s)
      s = Left(s, Len(s) - 2) & " " & Right(s, 2)
      Cells(i, ColumnNumber).Value = s
   End If
Next i
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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