View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Kevin B Kevin B is offline
external usenet poster
 
Posts: 1,316
Default Left Justify Rows of Numbers

The following example assumes that the 2 columns of data are Columns A and B
and it starts running with the cellpointer in first value in column B
================================================== ====
Sub MoveToBlankCell()

Dim wb As Workbook
Dim ws As Worksheet
Dim varVal As Variant
Dim iRowCounter As Integer

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")

Range("B1").Select

varVal = ActiveCell.Value

Do Until varVal = ""
If ActiveCell.Offset(iRowCounter, -1).Value = "" Then
ActiveCell.Offset(iRowCounter).Cut
ActiveCell.Offset(iRowCounter, -1).Delete Shift:=xlShiftToLeft
End If
iRowCounter = iRowCounter + 1
varVal = ActiveCell.Offset(iRowCounter).Value
Loop

Set wb = Nothing
Set ws = Nothing

End Sub
================================================== ====
--
Kevin Backmann


"JG Scott" wrote:

I have a table in which each cell contains either a number or is blank.
On each row, I would like to delete all the blank cells to the left of
the first number and shift cells left.

Thanks.