Adding spaces automatically

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
So My sheet looks bad as cells text spill over into unused cells. I see if I add a "space" that will stop that from happening. Can anyone suggest a way to be able to search thru the sheet and if the cell is blank auto populate it with a "Space"?

Or even better a conditional formatting so it is automatic?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try
Code:
Sub addspace()
ActiveSheet.UsedRange.SpecialCells(xlBlanks).Value = " "
End Sub
 
Upvote 0
For the range A1:M9 (can be changed) . This is the code for macro.

Code:
Sub Macro1()

Range("A1:M9").SpecialCells(xlCellTypeBlanks).Value = " "


End Sub
 
Upvote 0
For the range A1:M9 (can be changed) . This is the code for macro.
Code:
Sub Macro1()

  Range("A1:M9").SpecialCells(xlCellTypeBlanks).Value = " "

End Sub
If the OP's data should occupy a lot more cells and if there are a considerable number of blank cells, perhaps it would be better to only fill the blank cells immediately to the right of a filled cell with a space character instead of putting the space character into every blank cell in the range. If the OP would like to pursue this approach, all he has to do is replace your single line of code with this one...
Code:
[table="width: 500"]
[tr]
	[td]Range("A1:M9").SpecialCells(xlConstants).Offset(, 1).SpecialCells(xlBlanks).Value = " "[/td]
[/tr]
[/table]
Also, I would note that if the OP's data spans to Column M, then the address in the Range object call should be changed to A1:N9 so that the filled cells in Column M (the last data column in the range) do not spill out into the adjacent unfilled cells (assuming that is what the OP wants).
 
Last edited:
Upvote 0
Also, I would note that if the OP's data spans to Column M, then the address in the Range object call should be changed to A1:N9 so that the filled cells in Column M (the last data column in the range) do not spill out into the adjacent unfilled cells (assuming that is what the OP wants).
But if the OP's UsedRange only extends to column M, then the empty cells in column N will not form part of the SpecialCells(xlBlanks) range and therefore still not get filled by that line of code.
 
Upvote 0
But if the OP's UsedRange only extends to column M, then the empty cells in column N will not form part of the SpecialCells(xlBlanks) range and therefore still not get filled by that line of code.
Hmm! Good point! I guess two lines of code would be needed with my method then...
Code:
[table="width: 500"]
[tr]
	[td]Range("A1:M9").SpecialCells(xlConstants).Offset(, 1).SpecialCells(xlBlanks).Value = " "
Columns("M").SpecialCells(xlConstants).Offset(, 1).Value = " "[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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