0% found this document useful (0 votes)
25 views2 pages

Excel Macros

The document describes various Excel macro functions for formatting cells including printing text, arithmetic operations, alignment, background color, borders, cell referencing, copying/pasting data, and font color. It provides code examples for macros that perform each of these formatting tasks through actions like changing interior colors, border styles, font colors, and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

Excel Macros

The document describes various Excel macro functions for formatting cells including printing text, arithmetic operations, alignment, background color, borders, cell referencing, copying/pasting data, and font color. It provides code examples for macros that perform each of these formatting tasks through actions like changing interior colors, border styles, font colors, and more.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. Write a macro to print some text in message box.

Sub mac1()
MsgBox "EXCEL IS A analysis tool"
MsgBox 100
End Sub
2. Apply arithmetic operations on two cells using macros.
Sub add_values()
Range("g12").Value = Range("f5").Value - Range("f6").Value
End Sub
3. How to align the text using macros.
Sub align()
Range("a1:c5").HorizontalAlignment = xlLeft
Range("a1:c5").HorizontalAlignment = xlRight
Range("a1:c5").HorizontalAlignment = xlCenter
Range("a1:c5").VerticalAlignment = xlTop
Range("a1:c5").VerticalAlignment = xlBottom
Range("a1:c5").VerticalAlignment = xlCenter
End Sub

4. How to change the background color of the cells using macros.

Sub background_color()
Range("a1:a10").Interior.Color = vbRed
Range("a1:a10").Interior.Color = vbWhite
Range("a1:a10").Interior.Color = vbGreen
Range("a1:a10").Interior.Color = vbYellow
Range("a1:a10").Interior.Color = vbBlack
Range("a1:a10").Interior.Color = vbBlue
Range("a1:a10").Interior.Color = vbMagenta
Range("a1:a10").Interior.ColorIndex = 1
Range("a1:a10").Interior.ColorIndex = 10
Range("a1:a10").Interior.ColorIndex = 20
Range("a1:a10").Interior.ColorIndex = 56
End Sub

5. How to change the border color and style of the cells using macros.
Sub border()
Range("a1:a10").borders.Color = vbRed
Range("a1:a10").borders.Weight = 3
Range("a1:a10").borders.LineStyle = xlDot
Range("a1:a10").borders.LineStyle = xlDash
Range("a1:a10").borders.LineStyle = xlContinuous
Range("a1:a10").borders.LineStyle = xlDouble
Range("a1:a10").borders.LineStyle = xlNone

End Sub

6. Use cell referencing using macros.


Sub cell_ref()
ActiveCell.Value = "excel macro cell referencing"
ActiveCell.Value = 40
[b5].Value = 76
[c1:c10] = "hellogwerhbqek"
Cells(8, 2).Value = "row 8 col 2"
Range("a1") = "Cell A1"
Range("d11:d20").Value = "Another Range"
End Sub

7. How to copy the data from one cell and paste it into another.
Sub copy_paste()
Range("a1:a10") = "Tutorial"
Range("b1:b10") = Range("a1:a10").Value

'2nd method
Range("a1:a10").Copy
Range("d1:d10").PasteSpecial
Application.CutCopyMode = False

End Sub
8. How to change the font color of the text in a cell using macros.
Sub font_color()
Range("a1:c6").font.Color = vbGreen
Range("b7:c10").font.Color = vbWhite
Range("b7:c10").font.Color = vbYellow
Range("b7:c10").font.Color = vbBlue
Range("b7:c10").font.Color = vbCyan
Range("b7:c10").font.Color = vbMagenta
Range("b7:c10").font.Color = vbRed
Range("b7:c10").font.ColorIndex = 1
Range("b7:c10").font.ColorIndex = 10
Range("b7:c10").font.ColorIndex = 56

Range("a1:c6").font.Color = vbGreen

End Sub

You might also like