Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-19-2016, 11:02 PM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default Help with some VBA code Required

Good Morning All
I have some Excel VBA code that I require some help with.
Currently this code Color codes column's 2 To 3 ,is there a easy way to adapt code to also color code columns 10 To 16 at the same time.

Cheers
David
Attached Files
File Type: txt MarkWinners.txt (2.3 KB, 11 views)

Last edited by dmcg9760; 02-19-2016 at 11:30 PM. Reason: added which program
Reply With Quote
  #2  
Old 02-20-2016, 12:25 PM
charlesdh charlesdh is offline Help with some VBA code Required Windows 7 32bit Help with some VBA code Required Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

I add another loop for columns 10 to 16. You may need to review it. I did not check to see if the loop I added needed to be changed in any way.

Code:
Sub MarkWinners(ws As Worksheet)

    Dim l_row As Long

    

    With ws

        .Columns("D:D").NumberFormat = "General"

        .Columns("G:G").NumberFormat = "General"

        .Columns("I:I").NumberFormat = "General"

        For col = 2 To 3

         l_row = .Cells(.Rows.Count, col).End(xlUp).Row

            r = 3

            Do While r <= l_row

                ref_row = r

                win1 = .Range("E" & ref_row)

                'Find 4th

                pl4 = 0

                For rWinner = ref_row To ref_row + 8

                    If InStr(1, .Range("E" & rWinner), "*") > 0 Then

                        pl = Split(.Range("E" & rWinner), "*")

                        If UBound(pl) >= 3 Then

                            pl4 = Val(pl(3))

                            Exit For

                        End If

                    End If

                Next rWinner

                

                If win1 = "" Then

                    r = r + 9

                Else

                    

                    win2 = .Range("E" & ref_row + 1)

                    win3 = .Range("E" & ref_row + 2)

                    

                    r_runner = r

                    On Error Resume Next

                    Do While Not IsEmpty(.Cells(r_runner, col))

                        If Not IsError(.Cells(r_runner, col)) Then

                            If InStr(1, .Cells(r_runner, col), win1) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(148, 208, 80)   'Green

                            ElseIf InStr(1, .Cells(r_runner, col), win2) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(255, 192, 0)    'Amber

                            ElseIf InStr(1, .Cells(r_runner, col), win3) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(255, 0, 0)      'Red

                            ElseIf Val(Left(.Cells(r_runner, col), 2)) = pl4 Then

                                .Cells(r_runner, col).Interior.Color = RGB(0, 176, 240)    'Blue

                            End If

                        End If

                        r_runner = r_runner + 1

                    Loop

                    r = r_runner + 1

                End If

            Loop

        Next col
        '''''''''''''''''''  New Loop for column 10 to 16 '''
For col = 10 To 16

         l_row = .Cells(.Rows.Count, col).End(xlUp).Row

            r = 3

            Do While r <= l_row

                ref_row = r

                win1 = .Range("E" & ref_row)

                'Find 4th

                pl4 = 0

                For rWinner = ref_row To ref_row + 8

                    If InStr(1, .Range("E" & rWinner), "*") > 0 Then

                        pl = Split(.Range("E" & rWinner), "*")

                        If UBound(pl) >= 3 Then

                            pl4 = Val(pl(3))

                            Exit For

                        End If

                    End If

                Next rWinner

                

                If win1 = "" Then

                    r = r + 9

                Else

                    

                    win2 = .Range("E" & ref_row + 1)

                    win3 = .Range("E" & ref_row + 2)

                    

                    r_runner = r

                    On Error Resume Next

                    Do While Not IsEmpty(.Cells(r_runner, col))

                        If Not IsError(.Cells(r_runner, col)) Then

                            If InStr(1, .Cells(r_runner, col), win1) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(148, 208, 80)   'Green

                            ElseIf InStr(1, .Cells(r_runner, col), win2) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(255, 192, 0)    'Amber

                            ElseIf InStr(1, .Cells(r_runner, col), win3) > 0 Then

                                .Cells(r_runner, col).Interior.Color = RGB(255, 0, 0)      'Red

                            ElseIf Val(Left(.Cells(r_runner, col), 2)) = pl4 Then

                                .Cells(r_runner, col).Interior.Color = RGB(0, 176, 240)    'Blue

                            End If

                        End If

                        r_runner = r_runner + 1

                    Loop

                    r = r_runner + 1

                End If

            Loop

        Next col
    End With
End Sub
Reply With Quote
  #3  
Old 02-21-2016, 03:23 AM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default

Hi Charlesdh

Thank you very much for the reply, it is much appreciated

I have inserted the code text into the VBA and now it only seems to mark up the first lot of data and does not continue down through the page.

I have attached a sheet for you to see the outcome results.

Kind Regards
David
Attached Files
File Type: xlsx Report21022016 14-55.xlsx (59.0 KB, 13 views)

Last edited by dmcg9760; 02-21-2016 at 03:48 AM. Reason: spelling mistake
Reply With Quote
  #4  
Old 02-21-2016, 11:30 AM
charlesdh charlesdh is offline Help with some VBA code Required Windows 7 32bit Help with some VBA code Required Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

Please provide you workbook with the code.


Added:
As mentioned you will need to revamp the second loop for the desired columns.

Last edited by charlesdh; 02-21-2016 at 11:37 AM. Reason: Added information
Reply With Quote
  #5  
Old 02-21-2016, 05:57 PM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default

Hi,
The file is quite large and I am not able to upload it on here. the file even compressed is 1.4MB, original file is 2.33MB
Do you have a email address that I can forward a link to my Dropbox shared files.

David
Reply With Quote
  #6  
Old 02-23-2016, 06:09 PM
charlesdh charlesdh is offline Help with some VBA code Required Windows 7 32bit Help with some VBA code Required Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

HI,

Sorry I have not responded. But, did you create the code? If so you may be able to look at the code I posted and make the necessary correction for your file.
Reply With Quote
  #7  
Old 02-23-2016, 06:35 PM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default

Hi Charles

Sorry I am very new to code.

I have pasted the code in that you sent me, as requested,But the spreadsheet only color codes as per the sheet I attached.

The workbook as a whole has a lot of code that I have had written through freelancers with some very complicated formulas that are a bit beyond my ability in excel.

But I am slowly working through the issues and learning more and more all the time.

Any further help would be very much appreciated.

Cheers
David
Reply With Quote
  #8  
Old 02-24-2016, 12:07 PM
charlesdh charlesdh is offline Help with some VBA code Required Windows 7 32bit Help with some VBA code Required Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

The code I provided seems to work. If not tell me what part of the spreadsheet did not produce the desired out come.
Reply With Quote
  #9  
Old 02-26-2016, 06:21 AM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default

Hi Charles

It only does the first lot of data for each venue, If you look at the attached file ( Report26022016 20-39 ) from todays output you will see that in Horse Racing Tab columns J : P only the one race has been color coded instead of all down the page J:P columns,
What I am trying to get is when the runners number or name appears in column D & E the sheet also color codes down the page the same as like columns B & C like it has done in column J2:P6 but none of the rest of J:P down the page till the next venue.
Venue is in Column A : Sunshine Coast 1 , Sunshine Coast 2 and so on the next venue starts A57 : Moonee Valley 1 , Moonee valley 2 and so on down the page
Sorry hopefully that makes sense

Cheers
David
Attached Files
File Type: xlsx Report26022016 20-39.xlsx (319.8 KB, 11 views)
Reply With Quote
  #10  
Old 03-01-2016, 03:59 PM
dmcg9760 dmcg9760 is offline Help with some VBA code Required Windows 7 64bit Help with some VBA code Required Office 2010 64bit
Novice
Help with some VBA code Required
 
Join Date: Sep 2015
Posts: 19
dmcg9760 is on a distinguished road
Default

Good Morning Charles
Did you receive the emailed Excel file
Just following up on your thoughts about the file.
David
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Activation required, except I've already done that? Mir Office 1 04-01-2013 06:38 PM
Excel 2007 - formula or macro/vba code required wrighty50 Excel Programming 3 05-13-2012 02:24 PM
Help with some VBA code Required What IF statement required dr4ke Excel 8 09-01-2011 07:41 AM
Help with some VBA code Required Help required with spacing rohanmalhotra Word VBA 3 08-11-2011 04:06 AM
Suggestion required domex Word 0 10-06-2010 05:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft