0% found this document useful (0 votes)
25 views

Exercise - 9 Date:-: Aim:-Sort The Numbers Stored in The Excel Files and Change The Color of The Cell

This document contains code to open an Excel file, sort the numbers in the first column in ascending order, and change the interior color of the first 5 cells in the first column to red, yellow, green, blue, and white respectively. The code sets Excel application objects to open a workbook, get the used range and first cell, sorts the range based on the first cell in ascending order, and sets the interior colors of the first 5 cells.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Exercise - 9 Date:-: Aim:-Sort The Numbers Stored in The Excel Files and Change The Color of The Cell

This document contains code to open an Excel file, sort the numbers in the first column in ascending order, and change the interior color of the first 5 cells in the first column to red, yellow, green, blue, and white respectively. The code sets Excel application objects to open a workbook, get the used range and first cell, sorts the range based on the first cell in ascending order, and sets the interior colors of the first 5 cells.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXERCISE - 9

Date:-

Aim:- Sort the numbers stored in the excel files and change the color of the cell
Coding:-

Const xlAscending = 1
Const xlYes = 0
Set myxl = CreateObject("Excel.Application")
myxl.Visible = True
Set myxlWorkbook = _
myxl.Workbooks.Open("Z:\rupesh.xlsx")

Set myxlWorksheet = myxlWorkbook.Worksheets(1)


Set myxlRange = myxlWorksheet.UsedRange
Set myxlRange2 = myxl.Range("A1")
myxlRange.Sort myxlRange2, xlAscending, , , , , , xlYes
myxl.cells(1,1).Interior.Color=vbRed
myxl.cells(2,1).Interior.Color=vbYellow
myxl.cells(3,1).Interior.Color=vbGreen
myxl.cells(4,1).Interior.Color=vbBlue
myxl.cells(5,1).Interior.Color=vbWhite
set myxl=nothing

output

You might also like