Add space with vba at the begining of text

scorpio3st

New Member
Joined
Sep 7, 2021
Messages
22
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi,

Please can you help me to add space at the beginning of word (Sheet name="Lista1, range Column "J"?
I need macro.
Thanks.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
For every cell in column J:

VBA Code:
Sub jec()
 For Each it In Sheets("Lista1").Range("J1", Sheets("Lista1").Cells(Rows.Count, "J").End(xlUp))
   it.Value = " " & it.Value
 Next
End Sub
 
Upvote 0
Solution
For every cell in column J:

VBA Code:
Sub jec()
 For Each it In Sheets("Lista1").Range("J1", Sheets("Lista1").Cells(Rows.Count, "J").End(xlUp))
   it.Value = " " & it.Value
 Next
End Sub
Thanks. Works perfect.
 
Upvote 0
Another option is to do them all at once rather than cell-by-cell.

add space at the beginning of word
Further, if you happen to have any blank cells in the range, this will also leave them blank (rather than adding a space to the blank cell) as there is no word to put the space before.

VBA Code:
Sub AddSpace()
  With Sheets("Lista1").Range("J1", Sheets("Lista1").Range("J" & Rows.Count).End(xlUp))
    .Value = Evaluate(Replace("if(#="""","""","" ""&#)", "#", .Address(External:=True)))
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,195
Latest member
Stevenciu

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