Can i quicken this Function or use diff code to speed it Up

mahmed1

Well-known Member
Joined
Mar 28, 2009
Messages
2,302
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi

I have this function that is used on several sheets and the The range to lookin is in B2:I200 therefore it loops several of times when this function is called or when a cell changes within that range on that sheet

I double on a cell to change its colour and add a value and then this function is called to sum the colour

This works fine but can be clunky at times

Need help speeding it up or using different method

Here is the working Code:

Code:
Function SumColour(MatchColour As Range, MatchColourRange) As Double
Dim Cell As Range
Application.ScreenUpdating = False
For Each Cell In MatchColourRange
    If Cell.Interior.Color = MatchColour.Interior.Color Then
        On Error Resume Next
        SumColour = SumColour + Cell.Value
        On Error GoTo 0
    End If
Next Cell
Application.ScreenUpdating = True
End Function
 
Either the name is wrong, or you need to specify which workbook.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi

the sheet names are definately correct and the workbook i an running code is the workbook with the sheets
 
Upvote 0
the sheet names are definately correct...
When you say that, your sheet names (on the worksheet's tabs) definitely say Sheet1, Sheet2, Sheet3 and Sheet4 because that is what this line of code expects them to be... the actual name on the tab, not the generic sheet position (code) name...

SheetNames = Array("Sheet1", "Sheet2", "Sheet3", "Sheet4")
 
Upvote 0
Hi have

sheet tab names sheet1, then a sheetname called index which im ignoring and then sheet2,sheet3
 
Upvote 0
Hi there are sheets (sheet1 to sheet4)
i have many other sheets in my workbook but those are the 4sheete that will be worked/processed on
 
Upvote 0
Any luck rick?

i suppose i could do a for each loop to say if the sheet name is not 1 of the sheets then skip over it but still curious to why your code wont work. Based on what rory has said, would i need to qualify as thisworkbook.worksheets(SN)?
 
Upvote 0
Any luck rick?

i suppose i could do a for each loop to say if the sheet name is not 1 of the sheets then skip over it but still curious to why your code wont work. Based on what rory has said, would i need to qualify as thisworkbook.worksheets(SN)?
I am at a loss what to tell you. The only way this line of code...

Set WS = Worksheets(SN)

could fail with a subscript out of range error is if the text assigned to SN is not the name on any of your tabs. Can you send me a copy of the workbook that my code does this on? Maybe I'll be able to spot the problem by watching the code work, step-by-step, up to the point where it fails. My email address is...

rick DOT news AT verizon DOT net
 
Upvote 0
Hi Rick

Silly Me

The sheet had a double space in there which i did not realise until i tested the length of the tab name

thank you, you have been amazing
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top