Solved

VBA Code

Posted on 2011-02-16
9
190 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
 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 250 total points
ID: 34908853
Seamus - what about Fernando's suggestion, might be simpler?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

896 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

17 Experts available now in Live!

Get 1:1 Help Now