+ Reply to Thread
Results 1 to 33 of 33

Conditionally Format in VBA

  1. #1
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Conditionally Format in VBA

    Links to my spreadsheet
    Pre
    https://drive.google.com/file/d/1fQs...ew?usp=sharing

    Final Product
    https://drive.google.com/file/d/1Msm...ew?usp=sharing


    I've almost fully coded the vba to achieve my desired results but I'm not sure how to conditionally format with VBA.

    I want to conditionally format the spreadsheet. Highlighting full rows where sold IS NOT = 0 in green, individual cells where % distant is greater than 50% in yellow, and last disposition is over 1 hour earlier than the max time of the last disposition row also in yellow.

    Please help. The code I have so far is below

    Please Login or Register  to view this content.
    Last edited by alansidman; 01-25-2018 at 08:59 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    I added the following codes

    Removes Grouping, Filtering, then Sort by SOLD {smallest to largest}
    Please Login or Register  to view this content.
    Color Range("A2:J120") Green IF Range("I2:I) > 0
    Please Login or Register  to view this content.

    Here's the complete code
    Please Login or Register  to view this content.
    Quote Originally Posted by dizjackson View Post
    last disposition is over 1 hour earlier than the max time of the last disposition row also in yellow.
    Requesting additional information on the thinking behind the Last Disposition request.
    Last edited by Syrkrasi; 12-20-2017 at 03:36 PM. Reason: Updated Color Range("A2:J120") Code
    If your original question was resolved, please select "Thread Tools" from the menu link above and mark this thread as SOLVED.
    Click on the Add Reputation button (located at the lower-left corner of all post) for those who assisted you in solving your issue.

  3. #3
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Thank you so much for your help. The thinking behind the Last Disposition request is that I want to highlight any disposition that is over an hour from the current time but I'm guessing it would be kind of difficult to base my spreadsheet on RealTime, I figured it would be easier to just base it off the latest disposition in that column. Also, every time I run the macro, I'm losing one too many rows from the bottom of the spreadsheet. Could you please inspect the code below for a possible cause. Thanks
    Please Login or Register  to view this content.
    Last edited by daddylonglegs; 01-25-2018 at 02:20 PM.

  4. #4
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Quote Originally Posted by dizjackson View Post
    every time I run the macro, I'm losing one too many rows from the bottom of the spreadsheet. Could you please inspect the code below for a possible cause.
    I've made some minor changes to the code

    I replaced the un-merging portion (which took forever under testing mode)
    Please Login or Register  to view this content.
    I also replaced the third deletion portion of your code which searches & deletes rows based on the word Total
    Please Login or Register  to view this content.
    Here is the revised code
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    I'm getting an error message:
    Run-time error '424': Object required

  6. #6
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    I do not get an error when using your sample file; however, I did noticed that I left out Dim r As Integer

    Please Login or Register  to view this content.
    Let me know if this fixes the error

  7. #7
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    I've added that line but I'm still getting the same error message. Could it be because the name of my workbook is "Time Track (with Macro)" instead of "Time Track". And I've changed the name to Sub KnockReport(). Please assist

    Please Login or Register  to view this content.
    Last edited by daddylonglegs; 01-25-2018 at 02:21 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    You're not compliant to the Forum Rules especially to RULE #3:

    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window (if you are editing an existing post, press Go Advanced to see the [#] button). The result will appear like this in the post window:

    ['code]
    your code here ...
    and here ...
    and here
    [/code]

    ... and appear like this when posted:

    Please Login or Register  to view this content.
    How are you running the macro? are you running it within said file or from another macro workbook?
    As far as I can see, you're still using the old code. Please see post #4

  9. #9
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Sorry for the delay. Code below

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    You haven't answered my question on how you're running the code. see post #8.

    The code you just provided (which is similar to your original) does not work properly. It's deleting too many rows, and it doesn't perform the second part of your request.

    Please try the code listed below, but do let me know if you run into any issues (as I have not.) thx

    Please Login or Register  to view this content.
    Edit: Attached is the file I downloaded from the site you provided, and re-saved as a macro-enabled file (code included).
    Attached Files Attached Files
    Last edited by Syrkrasi; 01-16-2018 at 04:41 PM. Reason: Attached OP's file with code

  11. #11
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    I’m running it within the filebby clicking view —> macros —> run macros. I’m still receiving the run time error ‘424: Object Required error. Debug takes me to the line For r = sheet1.UsedRange.Rows.Count to 1 Step -1

  12. #12
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Please download and run the macro within the file I submitted in post 10.

    I had three individuals run it on three different OS's (Win 7 pro, 8, 10), and all stated that they did not receive an error.

    Confirm when done

  13. #13
    Forum Expert
    Join Date
    04-01-2013
    Location
    East Auckland
    MS-Off Ver
    Excel 365
    Posts
    1,343

    Re: Conditionally Format in VBA

    I note it works well for me (without error).
    If you want something done right... find a forum and ask an online expert.

    Time flies like an arrow. Fruit flies like a banana.

  14. #14
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    I'm not sure what's going on with mine. I downloaded the exact file from post 10 and running the macro but I'm still receiving the same error. Any settings I need to change with my excel or anything? I feel so close haha

  15. #15
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Quote Originally Posted by scottiex View Post
    I note it works well for me (without error).
    Thanks scottiex for the confirmation

  16. #16
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    When I run this macro on the Time_Track tab I don't receive an error message but it's also not deleting the rows with an empty cell in column A which is important. When I create a new tab to copy and paste a new table and run that macro, that's when I receive the error. Sorry I wasn't being clear about the steps I was taking before

    What I'm getting looks like this
    Capture.PNG

    I want it to look like this (without deleting an extra bottom row)
    Capture2.PNG

  17. #17
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Also, instead of highlighting the cells yellow where disposition is greater than 50%, I want to fill those cells yellow.

  18. #18
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Quote Originally Posted by dizjackson View Post
    I'm not sure what's going on with mine. I downloaded the exact file from post 10 and running the macro but I'm still receiving the same error. Any settings I need to change with my excel or anything? I feel so close haha
    There are no settings that needs to be set. Can you try it on another system? This will help us rule out being an issue with the code.

    Thanks

  19. #19
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Quote Originally Posted by dizjackson View Post
    When I create a new tab to copy and paste a new table and run that macro, that's when I receive the error.
    ok that makes since. The code looks at Sheet1 or Sheets("Time_Track")

    I'll make changes to the code to reflect the requirements in post #16

  20. #20
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    You're awesome!

  21. #21
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    The raw data report is formatted so weird it's difficult to easily get what I want without a macro. Any idea how I could also add a table that shows how many sales each team has, based on the 'sold' column for that group. It would be nice to be able to customize the team names as well. Adding this, even to another sheet would really be beneficial as well. I'm not sure where to start with that piece

    Something like this

    Capture.PNG

  22. #22
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Actually, something more like the chart below. Where the reps with sales columns is the count of reps who have a sale in each group. Thank You!

    Capture.PNG

  23. #23
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,594

    Re: Conditionally Format in VBA

    deleted....
    Last edited by protonLeah; 01-24-2018 at 03:53 PM.
    Ben Van Johnson

  24. #24
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Which post are you referring to? The posts I have with code don't give me the option to edit.

  25. #25
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,851

    Re: Conditionally Format in VBA

    @dizjackson

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  26. #26
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Excelers,

    This post was locked for a couple of days. Any new assistance with the issue I was having?

    Thank You

  27. #27
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Sorry for the delay. Someone decided that my house was a five-finger discount store and cleaned me out.

    any way...

    I've completed your request (from post #16). see code and attached test file

    Please Login or Register  to view this content.
    Attached Files Attached Files

  28. #28
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    Thank You. I'm still losing an extra line (name) at the bottom after running the macro. Please assist

  29. #29
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    Quote Originally Posted by dizjackson View Post
    I'm still losing an extra line (name) at the bottom after running the macro.
    I manually ran your process, and I came up with the same results.
    1. There are 130 records (excluding the header) in the initial file.
    2. After running your deletion sequence, there are 67 out of 120 records where column A is blank
    3. After deleting rows where column A is blank, there are 53 records left

    Which is missing from your list? Here is mine.
    • 8 Roger Rabbit
    • 8 Buggs Bunny
    • 6 Austin Powers
    • 9 MC Hammer
    • 5 Ric Flair
    • 9 Tom Brady
    • 8 Michael Jordan

  30. #30
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    After running the updated macro, I end up with 7 Michael Jordan's instead of 8.

  31. #31
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    I am not sure why you're getting one less record.
    I receive the same results as in post #29 regardless if I run it manually or by the script.
    Are you running the code listed in post #27? If not please do so and get back to me.
    Thanks

  32. #32
    Registered User
    Join Date
    09-14-2013
    Location
    Columbia, SC
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Conditionally Format in VBA

    I am using the file from post #27. I'm not sure why but when I run my original pre-filter file, I lose the Michael Jordan with start disposition 2:35pm and last disposition 5:09pm.

  33. #33
    Valued Forum Contributor
    Join Date
    12-01-2016
    Location
    Planet Earth
    MS-Off Ver
    95 - 2016
    Posts
    343

    Re: Conditionally Format in VBA

    I am not sure what you're doing wrong, or why you’re the only one that’s receiving 52 records instead of 53. Hence, I had 3 individuals, perform the following
    1. Download the file listed in your first initial post,
    2. Insert and run the macro listed in post #27

    They all came back with the same results as I stated in post #29.

    I cannot assist further on this thread, unless someone else on this forum comes up with the same results as you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Conditionally Format Bars
    By asleischow in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 07-01-2017, 04:48 AM
  2. Replies: 1
    Last Post: 01-04-2017, 06:00 PM
  3. Replies: 1
    Last Post: 01-04-2017, 05:59 PM
  4. [SOLVED] Conditionally format all rows until the last row.
    By themob212 in forum Excel General
    Replies: 3
    Last Post: 10-19-2016, 10:54 AM
  5. Replies: 1
    Last Post: 07-03-2014, 06:33 AM
  6. Format Conditionally with VBA
    By pilotwings64 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2012, 05:09 PM
  7. Trying to conditionally format
    By Speedbird1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-16-2008, 10:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1