Solved

VBA Code

Posted on 2011-02-16
9
191 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

813 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

18 Experts available now in Live!

Get 1:1 Help Now