VBA Code Modify Format Cell to have spaces at end for right justification

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Thanks in advance for your assistance. How would I modify the following line to get how many ever spaces I would like at the end of it. In this case let's say two so it changes from what I have in the first cell (D1) to the second cell (D2). They are both right justified, but D2 has two spaces at the end to ensure that it does not bunch up with what's in column E. See the code below the image.

1638320427019.png


This is what I have to format the cell currently. How would I modify?
VBA Code:
Range("D" & i).NumberFormat = "[>=1000000] #,##0.0,,"" m"";[>0] #,##0.0,"" k"";General"
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
in cell D2 type =d1&" " - Two spaces in the text brackets

VBA code is similar

Range("D2").Value = Range("D1").Value & " "

Jamie
 
Upvote 0
What about having no spaces at the right and format the whole column like this, thereby letting Excel do the alignment for you?

1638341548114.png
 
Upvote 0
in cell D2 type =d1&" " - Two spaces in the text brackets

VBA code is similar

Range("D2").Value = Range("D1").Value & " "

Jamie
Apologies actually I should have been clearer. I wanted to add spaces by showing them, but not actual spaces. I think I figured it out. See below.
 
Upvote 0
Thanks in advance for your assistance. How would I modify the following line to get how many ever spaces I would like at the end of it. In this case let's say two so it changes from what I have in the first cell (D1) to the second cell (D2). They are both right justified, but D2 has two spaces at the end to ensure that it does not bunch up with what's in column E. See the code below the image.

View attachment 52346

This is what I have to format the cell currently. How would I modify?
VBA Code:
Range("D" & i).NumberFormat = "[>=1000000] #,##0.0,,"" m"";[>0] #,##0.0,"" k"";General"

I think my original post might have not been clear as I wanted to do formatting by right justifying and have some room between the two columns, but not with actual spaces. Just look like spaces.

I changed the following:

VBA Code:
Range("D" & i).NumberFormat = "[>=1000000] #,##0.0,,"" m"";[>0] #,##0.0,"" k"";General"

to the following (see where "" m"" becomes "' m "" and "" k"" becomes "' k "" (i.e. put spaces before the last quote)

VBA Code:
Range("D" & i).NumberFormat = "[>=1000000] #,##0.0,,"" m  "";[>0] #,##0.0,"" k  "";General"
 
Upvote 0
Solution

Forum statistics

Threads
1,215,004
Messages
6,122,656
Members
449,091
Latest member
peppernaut

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