Solved

VBA Code

Posted on 2011-02-16
9
189 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
Comment Utility
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
Comment Utility
question: why don't you use conditional formatting ?
0
 

Author Comment

by:Seamus2626
Comment Utility
Off course i can, atatched ZIP

Thanks
Seamus
Example.zip
0
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 250 total points
Comment Utility
Seamus - what about Fernando's suggestion, might be simpler?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 24

Expert Comment

by:StephenJR
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you Fernando, and congratulations!
0
 

Author Comment

by:Seamus2626
Comment Utility
Congratulations Fernando!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now