VBA Code

Posted on 2011-03-11
Last Modified: 2012-05-11

I have attached a spreadsheet where i need some code to do two things

(1) Loop and find Grand total (never further than 500 rows, so can loop to A500
(2) Once found, make the next row size 6 with white fill (like in file) and the next 20 rows after that, filled with black

Question by:Seamus2626
LVL 85

Accepted Solution

Rory Archibald earned 500 total points
ID: 35110144
Try this:
Sub FormatIt()
   Dim rngFound As Range
   Set rngFound = Range("A:A").Find(what:="Grand total", LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
   If Not rngFound Is Nothing Then
      With rngFound
         With .Offset(1).Resize(, 7)
            .RowHeight = 6
            .Interior.Color = vbWhite
         End With
         With .Offset(2).Resize(20).EntireRow
            .Interior.Color = vbBlack
         End With
      End With
   End If
End Sub

Open in new window


Author Closing Comment

ID: 35110166

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question