Solved

VBA Code

Posted on 2011-02-16
9
193 Views
Last Modified: 2012-05-11
Hi, I need to create a sub that can do some formatting for me

The tab name is "Screen"

I need it to loop down Column A

When it reaches "Amount" , for Columns 2,3,4 fill Colour Index 35 (light green)
and Columns 5,6 Colur Index 2 (White)

for columns 2,3,4,5,6 have All Borders

I need it to loop down Column A until it finds "Count" and Do the Same

Then i need it to loop Column A Looking for all the below

"ASPA not posted"
"Booking adjustment required"
"Missed booking"
"Corporate Actions Booking Adjustment required"

On finding these i need it to fill Col 2,3,4 with Col Ind35 and 5,6 with Col Ind 3 (red)

for columns 2,3,4,5,6 have All Borders


Then

"Estimated dates/rates"
"Contra"
"Other"

On finding these i need it to fill Col 2,3,4 with Col Ind35 and 5,6 with Col Ind 51 (Dark Green)

for columns 2,3,4,5,6 have All Borders

Find "Grand Total" and for Columns 2,3,4,5,6

Fill Colour Index 2 (White)

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


As there is a lot there, if some one could get the sub going i should be able to work the rest out.

Thanks
Seamus
0
Comment
Question by:Seamus2626
  • 4
  • 3
  • 2
9 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 34908619
Seamus - could you post a mocked-up workbook illustrating at least some of this?
0
 
LVL 6

Accepted Solution

by:
FernandoFernandes earned 250 total points
ID: 34908626
question: why don't you use conditional formatting ?
0
 

Author Comment

by:Seamus2626
ID: 34908649
Off course i can, atatched ZIP

Thanks
Seamus
Example.zip
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 250 total points
ID: 34908853
Seamus - what about Fernando's suggestion, might be simpler?
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34908914
Seamus - let me know how this works as far as it goes. I'm aware it doesn't do everything but please check that it does the first block correctly.
Sub x()
  
Dim rFind As Range, sFind As String, sAddr As String, v, i As Long

v = Array("Amount", "Count", "ASPA not posted", "Booking adjustment required", "Missed booking", _
          "Corporate Actions Booking Adjustment required", "Estimated dates/rates", "Contra", _
          "Other", "Grand Total")
        
With Sheets("Screen").Columns(1)
    Set rFind = .Cells(1, 1)
    For i = LBound(v) To UBound(v)
        Set rFind = .Find(What:=v(i), After:=rFind, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
        Select Case i
            Case 0, 1
            If Not rFind Is Nothing Then
                rFind.Offset(, 1).Resize(, 3).Interior.ColorIndex = 35
                rFind.Offset(, 4).Resize(, 2).Interior.ColorIndex = 2
                rFind.Offset(, 1).Resize(, 5).Borders.LineStyle = xlContinuous
            End If
            Case 2, 3, 4, 5
            If Not rFind Is Nothing Then
                rFind.Offset(, 1).Resize(, 3).Interior.ColorIndex = 35
                rFind.Offset(, 4).Resize(, 2).Interior.ColorIndex = 3
                rFind.Offset(, 1).Resize(, 5).Borders.LineStyle = xlContinuous
            End If
            Case 6, 7, 8
            If Not rFind Is Nothing Then
                rFind.Offset(, 1).Resize(, 3).Interior.ColorIndex = 35
                rFind.Offset(, 4).Resize(, 2).Interior.ColorIndex = 51
                rFind.Offset(, 1).Resize(, 5).Borders.LineStyle = xlContinuous
            End If
            Case 9
            If Not rFind Is Nothing Then
                rFind.Offset(, 1).Resize(, 5).Interior.ColorIndex = 2
                rFind.Offset(, 1).Resize(, 5).Borders.LineStyle = xlContinuous
            End If
        End Select
    Next i
End With
     
End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 34908987
Sorry guys, just got back to my desk.

Your dead Fernando, much simpler, im trying to overcomplicate!!

Thanks for the code too Stephen.

Cheers guys,
Seamus
0
 
LVL 6

Expert Comment

by:FernandoFernandes
ID: 34909021
Stephen,
the code I was writing looked a lot like yours, especially with the Offset().Resize() :-)
Conditional formatting is the way to go... but codewise speaking, Stephen did great :)

Seamus, thanks for the points and the grade ! Today I'm happy because I just became Master, I am excited :-)
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 34909048
Thank you Fernando, and congratulations!
0
 

Author Comment

by:Seamus2626
ID: 34909139
Congratulations Fernando!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

808 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