VBA example - Excel 2007: loop to fill color last row


VBA code to fill color last row

Suppose that your Excel sheet contains the information as shown below. If you want to locate and fill color the last row that contains data, How can you do? You can do it simply by using VBA loop to find that row.

VBA for Excel
Excel 2007
VBA loop
VBA array


To run this example VBA code, you will need a Form, and a CommandButton. You may type the sample text above in to your current worksheet.


VBA for Excel: VBA loop to locate and fill color the last row that contains data


VBA code for this example:

Option Explicit Private Sub CommandButton1_Click()     Dim row As Integer     row = 1     While Trim(Cells(row, 1)) <> "" 'find the last row         row = row + 1     Wend      Range("A" & row - 1).Select 'select the last row and fill color     With Selection.Interior         .Color = RGB(20, 100, 10)     End With


Comments

Comments

Name:
Comment:
Enter the text:
CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.