Fill Blank Cells To Left

eran3185

Board Regular
Joined
Apr 28, 2007
Messages
142
Hi

I want to know if there is a way to to fill empty cells with value left.
i have this example:

e d c b a
1 Y X
2 Y X

I want to get this:
e d c b a
1 Y Y Y X X
2 Y X X
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
how do you see your rules, line one has 3 Y and 2 X for Y and X, how do you develop that
 
Upvote 0
Does this macro do what you want? Test on a copy of your workbook.
I have assumed there will always be at least one blank cell otherwise you wouldn't run the code.
Code:
Sub FillBlanksLeft()
  Application.ScreenUpdating = False
  With ActiveSheet.UsedRange
    .SpecialCells(xlBlanks).FormulaR1C1 = "=IF(COUNTA(RC[1]:RC[" & .Columns.Count & "]),RC[1],"""")"
    .Value = .Value
  End With
  Application.ScreenUpdating = True
End Sub

Before:


Book1
ABCDEF
1YX
2YX
Fill blanks



After:


Book1
ABCDEF
1YYYXX
2YXX
Fill blanks
 
Last edited:
Upvote 0
Hi peter.
Tnx again, but I have 1 more question/
Is there a way to run this code from left to right ?

Tnx
eran
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,766
Members
452,996
Latest member
nelsonsix66

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