deleting cells

L

Learner

I have this report from SAP, where data is not allligned with plenty of
empty cells, all over. The purpose of this program is to delete all empty
cells (ONLY) so that the data which is on the right, move to the left, on
column.. It is over 28 columns and proceeding from the far right going
left. The problems I have are 1) the code will delete data and 2) it will
not reach first column. I don't understand why. Your help will be
appreciated.
Thanks
Daniel

' Proceeding by column, bring to the left all data by deleting empty
cells
For x = colIndex - 1 To 1 Step -1 'Column
For y = rowMax To 1 Step -1 'Row
If IsEmpty(Cells(y, x)) And found = False Then
found = True 'found the first cell of the range (to be
deleted)
startCell = y
ElseIf IsEmpty(Cells(y, x)) And found = True Then
ElseIf Not IsEmpty(Cells(y, x)) And found = True Then
endCell = y + 1 'found data so stop for this range
Range(Cells(startCell, x), Cells(endCell, x)).Select
Range(Cells(startCell, x), Cells(endCell, x)).Delete
Shift:=xlShiftToLeft
found = False 'reset to continue up in the column
End If
Next
Next
 

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

Top