0% found this document useful (0 votes)
49 views4 pages

Macro Application: This Macro Works and Changes The Font To Bold Whenever The Cell Contains "1005"

The document contains several VBA macros that perform various tasks on Excel worksheets and cells. The macros format cells, count cells meeting certain criteria, sort data, find the last used cell in rows and columns, and display messages.

Uploaded by

bhavishya007
Copyright
© Attribution Non-Commercial (BY-NC)
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)
49 views4 pages

Macro Application: This Macro Works and Changes The Font To Bold Whenever The Cell Contains "1005"

The document contains several VBA macros that perform various tasks on Excel worksheets and cells. The macros format cells, count cells meeting certain criteria, sort data, find the last used cell in rows and columns, and display messages.

Uploaded by

bhavishya007
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 4

MACRO APPLICATION

Sub Test1()
This Macro Works and changes the font to bold whenever the cell contains 1005
For Each MyCell In Selection
If MyCell.Value Like "1005" Then
MyCell.Font.Bold = True
End If
Next
End Sub
----------------------------------------------------------------------------------------------------------------------------------Sub TestCondition2() This Macro Works
For Each Mycell In Selection
If Mycell.Value > "5000" Then
MsgBox "Target Achieved"
Else
MsgBox "Target Not Achieved"
End If
Next
End Sub
---------------------------------------------------------------------------------------------------------------------------------Sub TestCondition1() ' It works & makes the cell Bold and also Counts the No of cells whose value is < 1005
i=0
For Each mycell In Selection
If mycell.Value < "1005" Then
mycell.Font.Bold = True
i=i+1
End If
Next
Cells(1, 21).Value = i
' It puts the value of I into cell U1
End Sub
----------------------------------------------------------------------------------------------------------------------------------Sub Test1() ' It makes the range of cell Bold, colored and also Counts the No of cells whose value is < 1019 and > 1019
For Each MyCell In Selection
If MyCell.Value > "1019" Then
MyCell.Font.Bold = True
MyCell.Interior.ColorIndex = 4
gr = gr + 1
ElseIf MyCell.Value < "1019" Then
MyCell.Interior.ColorIndex = 6
sm = sm + 1
Else
MyCell.Interior.ColorIndex = 3
End If
Next
Cells(1, 21).Value = gr
Cells(1, 21).Interior.ColorIndex = 4
Cells(1, 22).Value = "Values >1019"
Cells(2, 21).Value = sm
Cells(2, 21).Interior.ColorIndex = 6
Cells(2, 22).Value = "Values<1019"
End Sub
-------------------------------------------------------------------------------------------------------------------------------------------

Sub Welcome() This Macro Woks


MsgBox "Welcome"
End Sub
-----------------------------------------------------------------------------------------------------------------------------------Sub LoopAdd1() 'It works & adds the value of column 1 and column 2 and puts the results in column3
x=1
Do While Cells(x, 1).Value <> ""
Cells(x, 3).Value = Cells(x, 1).Value + Cells(x, 2).Value 'column A+Column B=Column C
x=x+1
Loop
End Sub
-----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------------------------------

Sub sortdata() It Sorts the Nos in Ascending order


Dim a(10) As Integer
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Dim k As Integer
Dim rRange As Range
Dim rCell As Range
Set rRange = Range("W1", Range("W10").End(xlUp))
For Each rCell In rRange
For i = 1 To 10
a(i) = rCell(i).Value
Next i
Next rCell
For j = 0 To 9
For i = 0 To 9
If (a(i) > a(i + 1)) Then
temp = a(i)
a(i) = a(i + 1)
a(i + 1) = temp
End If
Next i
Next j
For Each rCell In rRange
For k = 1 To 10
rCell(k).Value = a(k)
Next k
Next rCell
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------Sub Test1() ' It makes the cell Bold,coloured and also Counts the No of cells whose value is < 1019 and > 1019 and 1019
For Each MyCell In Selection
If MyCell.Value > "1019" Then
MyCell.Font.Bold = True
MyCell.Interior.ColorIndex = 4
gr = gr + 1
ElseIf MyCell.Value < "1019" Then
MyCell.Interior.ColorIndex = 6
sm = sm + 1
Else
MyCell.Interior.ColorIndex = 3
ex = ex + 1
End If
Next
Cells(1, 21).Value = gr
Cells(1, 21).Interior.ColorIndex = 4
Cells(1, 22).Value = "Values >1019"
Cells(2, 21).Value = sm
Cells(2, 21).Interior.ColorIndex = 6
Cells(2, 22).Value = "Values<1019"
Cells(3, 21).Value = ex
Cells(3, 21).Interior.ColorIndex = 3
Cells(3, 22).Value = "Exact 1019"
End Sub

Find the last used cell, before a blank in a Column:


Sub LastCellBeforeBlankInColumn()
Range("A1").End(xldown).Select
End Sub
Find the very last used cell in a Column:
Sub LastCellInColumn()
Range("A65536").End(xlup).Select
End Sub
Find the last cell, before a blank in a Row:
Sub LastCellBeforeBlankInRow()
Range("A1").End(xlToRight).Select
End Sub
Find the very last used cell in a Row:
Sub LastCellInRow()
Range("IV1").End(xlToLeft).Select
End Sub
Find the very last used cell on a Worksheet:
Sub Demo()
Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Select
End Sub

You might also like