Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Conditional formatting of data exported to ExcelHelpful Member!(3) 

MeldrethMan (TechnicalUser) (OP)
19 Feb 12 3:46

I'm successfully sending data to Excel, code extract below

    Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblSelectedClients")
        rst.MoveFirst
        Do While Not rst.EOF
            objSht.Cells(iRow, 1).Value = rst!Name
            objSht.Cells(iRow, 2).Value = rst!Company
            objSht.Cells(iRow, 3).Value = rst!Address1
            objSht.Cells(iRow, 4).Value = rst!Address2
            objSht.Cells(iRow, 5).Value = rst!Address3
            objSht.Cells(iRow, 6).Value = rst!Town
            objSht.Cells(iRow, 7).Value = rst!County
            objSht.Cells(iRow, 8).Value = rst!Postcode
            objSht.Cells(iRow, 9).Value = rst!FirstName
            objSht.Cells(iRow, 10).Value = rst!LastName
            objSht.Cells(iRow, 11).Value = rst!Status
            iRow = iRow + 1
            rst.MoveNext
        Loop

I'd like to have conditional formatting in the resulting spreadsheet according to the value of Status. This can have several values so would like say

   If Status is Invoiced, colour the cell Red
   If Paid, then Green

Going a step further, colouring the entire spreadsheet row would be a real bonus.

Any steers would be much appreciated.

 
MeldrethMan (TechnicalUser) (OP)
19 Feb 12 8:55

Have found out how to do part of this for the Status cell, by adding

    If rst!Status = "Paid" then
          objSht.Cells(iRow,11).Interior.Color=RGB(200,100,35)
    etc for other Status values

Is there an easier way of applying the colour to the whole Excel row than having to repeat the formatting for (iRow,1) to (iRow,10)?
Helpful Member!  PHV (MIS)
19 Feb 12 9:57
I'd try this:
objSht.Cells(iRow,11).EntireRow.Interior.Color=RGB(200,100,35)

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Helpful Member!  TheAceMan1 (Programmer)
19 Feb 12 10:45
How are ya MeldrethMan . . .

Be aware ... the method you've shown is not Conditional Formatting. To perform this with no code perform the following (I'm using 2003):
  1. Select the range of cells you know will be involved. Remember the TopRow in your selection.
  2. On the menubar select Format - Conditional Formatting. The Conditional Formatting Dialog opens.
  3. In the far left combobox select Formula Is.
  4. Put the cursor in the textbox just to the right. Now ... assuming the TopRow in your selection is 1, enter $K1="Paid"
  5. Select the Format... button, make your selections and hit OK when your done.
  6. Select the Add >> button and perform steps 3 thru 5 for Invoiced ... $K1="Invoiced".
  7. Hit OK for final checkout.
  8. Thats It! ...
Your Thoughts? . . .

See Ya! .  .  .  .  .  .

Be sure to see FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?  Worthy Reading! thumbsup2
Also FAQ181-2886: How can I maximize my chances of getting an answer?  Worthy Reading! thumbsup2

MeldrethMan (TechnicalUser) (OP)
19 Feb 12 15:28
Thanks to you both, know I'm in safe hands with you guys.

PHV - Your suggestion
      objSht.Cells(iRow,11).EntireRow.Interior.Color=RGB(200,100,35)    
gave 'Application-defined or Object-defined error' but
      objSht.Cells.EntireRow.Interior.Color=RGB(200,100,35)  
colours the entire worksheet. I'll look for way of making it specific to the current row.

Ace - If I understand your suggestion it's to apply the formatting once the data arrives in Excel, which is fine, thanks.

 
TheAceMan1 (Programmer)
19 Feb 12 15:41

Quote (MeldrethMan):

... it's to apply the formatting once the data arrives in Excel, which is fine, thanks.
Yes. Conditional Formatting will pickup any cell changes in column K and format proper.

 

See Ya! .  .  .  .  .  .

Be sure to see FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?  Worthy Reading! thumbsup2
Also FAQ181-2886: How can I maximize my chances of getting an answer?  Worthy Reading! thumbsup2

Helpful Member!  Gammachaser (Programmer)
19 Feb 12 20:01

Conditional formatting can be applied through code. If you are going to let others use the spreadsheets and want them to stay within certain parameters, you can code the conditional formatting in to let them know when they exceed the limits. It is a little obscure at first, but it once you get the syntax, it is not hard to do.

If you are just making a 'static' spreadsheet where the users can't affect what makes the cells a certain color (i.e. in your case no one will cause the status to change by manipulating the spreadsheet) what you are doing works well.
 

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close