ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Color Cell throw macro (https://www.excelbanter.com/excel-programming/353353-color-cell-throw-macro.html)

nshanmugaraj

Color Cell throw macro
 

hi,
I am new to Excel programming...
can any one say how to write a macro to make a cell color = "green" and
the font = "bold" ... when cliking a button

i will be happy if you send me the coding since i am new to excel
programming


Thanks
N.ShRaj


--
nshanmugaraj
------------------------------------------------------------------------
nshanmugaraj's Profile: http://www.excelforum.com/member.php...o&userid=31570
View this thread: http://www.excelforum.com/showthread...hreadid=512644


Martin Fishlock[_4_]

Color Cell throw macro
 
Try this bit of code, it uses the selected cells:

Sub MakeCellGreenAndBold()
' uses the selected cell
With Selection
With .Interior
.ColorIndex = 35 ' or try 4 or 50
.Pattern = xlSolid
End With
.Font.Bold = True
End With
End Sub

--

change
.ColorIndex = 35 ' or try 4 or 50
to be 4 or 50 for a different color.

You then have to insert a button and assign the macro.

Note if you want a specific cell change

With Selection
to
With ActiveSheet.Range("A1")

HTHs Martin


"nshanmugaraj" wrote:


hi,
I am new to Excel programming...
can any one say how to write a macro to make a cell color = "green" and
the font = "bold" ... when cliking a button

i will be happy if you send me the coding since i am new to excel
programming


Thanks
N.ShRaj


--
nshanmugaraj
------------------------------------------------------------------------
nshanmugaraj's Profile: http://www.excelforum.com/member.php...o&userid=31570
View this thread: http://www.excelforum.com/showthread...hreadid=512644



AnExpertNovice

Color Cell throw macro
 
One way to learn syntax is to record a macro. Here is the code recorded:
With Selection.Font
.Name = "Courier New"
.FontStyle = "Bold"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With Selection.Interior
.ColorIndex = 14
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With

Recorded code is rarely complete. Not many, for example, would leave
..ColorIndex = 14 alone but would change the 14 to a variable name then
declare the variable. At the very least a comment would be added. Many of
the recorded lines *might* be eliminated.

To execute this code from a button.

Either add a button from the Control Tool box. Be sure to change the name
of the button. It is easier to understand what btnFormatFont does that if
the default name of CommandButton1 was kept. Then add a click event and
insert the recorded code.
Private Sub btnFormatFont_Click()
'Insert recorded code from above
End Sub

or

Add a button from the Forms toolbox and assign a macro. In this case you
will want to insert a module and create the macro first then add the button.
As always, rename your objects. Change the module name, the macro name, the
button name. This is not important in very short workbooks but it is a
habit you should consider learning.

good luck.


--
My handle should tell you enough about me. I am not an MVP, expert, guru,
etc. but I do like to help.


"nshanmugaraj"
wrote in message
news:nshanmugaraj.239s6m_1140005401.3076@excelforu m-nospam.com...

hi,
I am new to Excel programming...
can any one say how to write a macro to make a cell color = "green" and
the font = "bold" ... when cliking a button

i will be happy if you send me the coding since i am new to excel
programming


Thanks
N.ShRaj


--
nshanmugaraj
------------------------------------------------------------------------
nshanmugaraj's Profile:
http://www.excelforum.com/member.php...o&userid=31570
View this thread: http://www.excelforum.com/showthread...hreadid=512644




[email protected]

Color Cell throw macro
 
Also look at Conditional Formatting. This can make the colors you want
without specific code.

Glen


nshanmugaraj[_2_]

Color Cell throw macro
 

Hi
thanks for the code....
i am in specifically need to change the color of rows wihch satisfy a
condition

can u kindly help me please....


--
nshanmugaraj
------------------------------------------------------------------------
nshanmugaraj's Profile: http://www.excelforum.com/member.php...o&userid=31570
View this thread: http://www.excelforum.com/showthread...hreadid=512644


Norman Jones

Color Cell throw macro
 
Hi N,

See:

http://www.contextures.com/xlCondFormat02.html


---
Regards,
Norman



"nshanmugaraj"
wrote in message
news:nshanmugaraj.23av2m_1140055803.7723@excelforu m-nospam.com...

Hi
thanks for the code....
i am in specifically need to change the color of rows wihch satisfy a
condition

can u kindly help me please....


--
nshanmugaraj
------------------------------------------------------------------------
nshanmugaraj's Profile:
http://www.excelforum.com/member.php...o&userid=31570
View this thread: http://www.excelforum.com/showthread...hreadid=512644





All times are GMT +1. The time now is 03:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com