Insert a blank at the beginning of all cells in a specific column

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
I need to insert a space at the beginning of each cell so they all match.
So the first two rows would have to have the space inserted.
Is there a easy way to do this. VBS is a option if needed.


abc
abc
abc
abc
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
The sample data above should show
data in row 1 and 2 starts without a blank 'abc' 'abc'
data in row 3 and 4 starts with a blank ' abc' ' abc'

after inserting the blank beginning in each row the rows would look like this
' abc'
' abc'
' abc'
' abc'

I could manually insert the blank for a few rows but I have hundreds

Thanks
 
Upvote 0
Perhaps this? (run it from the sheet of interest & adjust the range/column to suit)

VBA Code:
Option Explicit
Sub Add_Space()
    Dim i As Long, ar
    ar = Range("A1", Cells(Rows.Count, "A").End(xlUp))
    
    For i = 1 To UBound(ar, 1)
        Select Case Left(ar(i, 1), 1)
            Case Is = " "
                ar(i, 1) = ar(i, 1)
            Case Else
                ar(i, 1) = " " & ar(i, 1)
        End Select
    Next i
    Range("A1", Cells(Rows.Count, "A").End(xlUp)).Value = ar
End Sub
 
Upvote 0
Solution
Perhaps this? (run it from the sheet of interest & adjust the range/column to suit)

VBA Code:
Option Explicit
Sub Add_Space()
    Dim i As Long, ar
    ar = Range("A1", Cells(Rows.Count, "A").End(xlUp))
   
    For i = 1 To UBound(ar, 1)
        Select Case Left(ar(i, 1), 1)
            Case Is = " "
                ar(i, 1) = ar(i, 1)
            Case Else
                ar(i, 1) = " " & ar(i, 1)
        End Select
    Next i
    Range("A1", Cells(Rows.Count, "A").End(xlUp)).Value = ar
End Sub
Thanks Kevin
 
Upvote 0

Forum statistics

Threads
1,223,938
Messages
6,175,528
Members
452,651
Latest member
wordsearch

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