LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #7   Report Post  
Posted to microsoft.public.scripting.vbscript,microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to insert the Thousands Separator (comma) in Excel?

On Jun 15, 2:04 pm, "ekkehard.horner"
wrote:
Highlander schrieb:



On Jun 14, 1:53 pm, urkec wrote:
"Highlander" wrote:


objExcel.ActiveSheet.Range("B:B").Select
objExcel.Selection.NumberFormat = "#,##0"
No need to select the column:


objExcel.ActiveSheet.Columns("B:B").NumberFormat = "#,##0"


--
urkec


That pares it down to just one line. Thanks urkec.


While we're on a roll, I have another question. I want to implement
conditional formatting; where if a cell value in Column C is greater
than 50000, then that cell font will be changed to bold. Recording a
macro gave me this:


Sub Bold_Column()
Columns("C:C").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue,
Operator:=xlGreater, _
Formula1:="50000"
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
End With
End Sub


I've tried transposing the code from this macro into my script, with
no luck. Any suggestions would be greatly appreciated.


Thanks!


- Dave


From your

Const xlDescending = 2
Const xlNormal = 1
Const xlCenter = -4108

code I gather, you'll have no problems to add the constants
for xlCellValue and xlGreater. That leaves you with the task to
convert the VBA named parameters like "Type:=xlCellValue" to
VBScript positional ones: Use the Excel/VBA documentation
to determine the prototype of the FormatConditions.Add method;
if you are lucky the method's parameter list looks like

Add Type, Operator, Formula1, Formula2

then you can write

Selection.FormatConditions.Add xlCellValue, xlGreater, "50000"

otherwise you'll have to distribute your values to the correct
positions. E.g.

Add Operator, Formula2, Type, Formula1

==

Selection.FormatConditions.Add xlGreater, , xlCellValue, "50000"

(use , , to skip (optional) parameters you can't/won't set)- Hide quoted text -

- Show quoted text -


Okay I've added these Constants:

Const xlCellValue = 1
Const xlGreater = 5

And then the following code works:

'~~ Insert Bold and Red Font for any value greater than 50000 in
Column C
objExcel.Range("C:C").Select
objExcel.Selection.FormatConditions.Delete
objExcel.Selection.FormatConditions.Add xlCellValue, xlGreater,
"50000"
With objExcel.Selection.FormatConditions(1).Font
.Bold = True
.ColorIndex = 3 'Red
.Italic = False
End With

There is one problem though. Some of the cells in Column C contain
text, not a number, and the text is getting changed to Bold and Red
font. I only want the font to change for cells that contain a number.
How do I exclude the text cells from the conditional formatting?

Thanks in advance!

- Dave

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
separator of thousands Antonio Excel Discussion (Misc queries) 0 April 4th 08 01:28 AM
How do I default separator for thousands when working in XLS in t. Kamal Singh Oberh Excel Worksheet Functions 3 April 30th 07 07:20 AM
Convert a number to text and add a comma separator for thousands prahz Excel Programming 2 December 7th 06 06:19 PM
thousands comma separator in VBA Wendy Francis Excel Discussion (Misc queries) 2 October 25th 05 01:14 AM
separator of thousands excelFan Excel Discussion (Misc queries) 2 December 27th 04 12:27 PM


All times are GMT +1. The time now is 10:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"