Solved

VBA Code

Posted on 2011-02-16
9
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

627 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