Multiple format in single line

aaryan bl

New Member
Joined
May 18, 2021
Messages
4
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Hi Guys,

How to write code for multiple formats for one range in 'single line'. (Like - Range("A1").NumberFormat = "@" & Range("A1").Font.Color = vbRed)
The above example is working in two line, but not working in single line. I want to do it in one line because the range is same(A1).

This is for example and it's working for paste function;
(Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks :=False)

Thanks,
Aaryan BL
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi & welcome to MrExcel.
Why do you need to put two lines of code on one line?
 
Upvote 0
I want to do it in one line because the range is same(A1).
You can't do it on one line, you need to put it inside a With/End With statement to apply it to the same range (you could cheat it by using : but it is still multiple lines really).
 
Upvote 0
Hi & welcome to MrExcel.
Why do you need to put two lines of code on one line?
Hi Fluff,

Because, both two lines of code referring to one cell/range. So, I want to write it in one line & it will look's clean if so. Why I'm asking is, i just thought it is possible like the below example in paste function;

(Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks :=False)

If it's not possible, then i will try With/End With function. Thank you

Regards,
Aaryan BL
 
Upvote 0
You can't do it on one line, you need to put it inside a With/End With statement to apply it to the same range (you could cheat it by using : but it is still multiple lines really).
Hi Mark,

Thank you, I'll try it.

Regards,
Aaryan BL
 
Upvote 0
Because, both two lines of code referring to one cell/range. So, I want to write it in one line & it will look's clean if so.
Number format and font colour change are 2 different instructions so 2 lines is the common practice, although probably not as common as With / End With.
i will try With/End With function
This is actually the cleanest way (in my opinion) even though it uses 4 lines instead of 2.
 
Upvote 0
Thank you for all replies & also please let me know how to end this thread. As this is my first query & don't know to close this.
 
Upvote 0
Less characters the more lines you have though
Do indent spaces count? :unsure:

In all honesty, I'm probably one of the least consistent when it comes to coding methods so maybe my opinions are not the best.
 
Upvote 0
please let me know how to end this thread.
There is no need to specifically close a thread. If one of the responses most answers your thread then you can mark it at the top right with 'Mark as solution'.
However, in this case I don't think anybody actually answered your question (because it is not possible) so no need do mark anything or 'close' the thread.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

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