Findformat interior color doesn't work on excel 2010

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

Hello everyone
I have the following code that is working well on office 365

Code: Select all

Sub Colored_Cell()
    Dim LastTableCell, LastColoredCell, ws As Worksheet, lr8 As Long
    Set ws = ThisWorkbook.Sheets("DATA")
    lr8 = ws.ListObjects("Table1").Range.Columns(8).Cells.Find("*", SearchDirection:=xlPrevious).Row
    
    Application.FindFormat.Clear
    Application.FindFormat.Interior.Color = 15261367
    
    LastColoredCell = ws.UsedRange.Find("", , , , , 2, , , True).Offset(, -3).Address
    
    LastTableCell = ws.Range("i" & lr8).Address
    
    ws.PageSetup.PrintArea = ws.Range(LastColoredCell, LastTableCell).Address
    Application.FindFormat.Clear

End Sub
When trying the same code on office 2010 it throws runtime error 91 (Object variable or With block variable not set)
Attached the file
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Findformat interior color doesn't work on excel 2010

Post by HansV »

I don't have Excel 2010 so I cannot test it. The code looks OK.
Best wishes,
Hans

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Hello
I am not sure if this is a great help, as I am unfamiliar with the .FindFormat function , but I do have Excel 2010 and 2007
I can tell you that your macro appears to error sometimes in my Excel 2007 because it does not find the interior color of 15261367

Here is a listing of the interior colors that I see in the Excel 2007 where your macro is erroring, - I am using this test macro applied to your worksheet, "DATA"

Code: Select all

 Sub WhatInteriorColor()
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Sheets("DATA")

Dim RngTemp As Range
    For Each RngTemp In Ws.UsedRange
        If RngTemp.Interior.Color = 15261367 Then
        Debug.Print "****  " & RngTemp.Interior.Color & "  ******   " & RngTemp.AddressLocal
        Else
        Debug.Print RngTemp.Interior.Color & "   " & RngTemp.AddressLocal
        End If
    Next RngTemp
End Sub

Code: Select all

 16777215   $B$14
16777215   $C$14
16777215   $D$14
16777215   $E$14
16777215   $F$14
16777215   $G$14
16777215   $H$14
16777215   $A$15
16777215   $B$15
16777215   $C$15
16777215   $D$15
16777215   $E$15
16777215   $F$15
16777215   $G$15
16777215   $H$15
16777215   $A$16
16777215   $B$16
16777215   $C$16
16777215   $D$16
16777215   $E$16
16777215   $F$16
16777215   $G$16
16777215   $H$16
16777215   $A$17
16777215   $B$17
16777215   $C$17
16777215   $D$17
15261110   $E$17
16777215   $F$17
16777215   $G$17
16777215   $H$17
16777215   $A$18
16777215   $B$18
16777215   $C$18
16777215   $D$18
16777215   $E$18
16777215   $F$18
16777215   $G$18
16777215   $H$18
16777215   $A$19
16777215   $B$19
16777215   $C$19
16777215   $D$19
16777215   $E$19
16777215   $F$19
16777215   $G$19
16777215   $H$19
16777215   $A$20
16777215   $B$20
16777215   $C$20
16777215   $D$20
16777215   $E$20
16777215   $F$20
16777215   $G$20
16777215   $H$20
16777215   $A$21
16777215   $B$21
16777215   $C$21
16777215   $D$21
16777215   $E$21
16777215   $F$21
16777215   $G$21
16777215   $H$21
16777215   $A$22
16777215   $B$22
16777215   $C$22
16777215   $D$22
16777215   $E$22
16777215   $F$22
16777215   $G$22
16777215   $H$22
16777215   $A$23
16777215   $B$23
16777215   $C$23
16777215   $D$23
16777215   $E$23
16777215   $F$23
16777215   $G$23
16777215   $H$23
16777215   $A$24
16777215   $B$24
16777215   $C$24
16777215   $D$24
16777215   $E$24
16777215   $F$24
16777215   $G$24
16777215   $H$24
16777215   $A$25
16777215   $B$25
16777215   $C$25
16777215   $D$25
16777215   $E$25
16777215   $F$25
16777215   $G$25
16777215   $H$25
16777215   $A$26
16777215   $B$26
16777215   $C$26
16777215   $D$26
16777215   $E$26
16777215   $F$26
16777215   $G$26
16777215   $H$26
16777215   $A$27
16777215   $B$27
16777215   $C$27
16777215   $D$27
16777215   $E$27
16777215   $F$27
16777215   $G$27
16777215   $H$27
16777215   $A$28
16777215   $B$28
16777215   $C$28
16777215   $D$28
16777215   $E$28
16777215   $F$28
16777215   $G$28
16777215   $H$28
16777215   $A$29
16777215   $B$29
16777215   $C$29
16777215   $D$29
16777215   $E$29
16777215   $F$29
16777215   $G$29
16777215   $H$29
16777215   $A$30
16777215   $B$30
16777215   $C$30
16777215   $D$30
16777215   $E$30
16777215   $F$30
16777215   $G$30
16777215   $H$30
16777215   $A$31
16777215   $B$31
16777215   $C$31
16777215   $D$31
16777215   $E$31
16777215   $F$31
16777215   $G$31
16777215   $H$31
16777215   $A$32
16777215   $B$32
16777215   $C$32
16777215   $D$32
16777215   $E$32
16777215   $F$32
16777215   $G$32
16777215   $H$32
16777215   $A$33
16777215   $B$33
16777215   $C$33
16777215   $D$33
16777215   $E$33
16777215   $F$33
16777215   $G$33
16777215   $H$33
16777215   $A$34
16777215   $B$34
16777215   $C$34
15773696   $D$34
16777215   $E$34
15773696   $F$34
16777215   $G$34
16777215   $H$34
16777215   $A$35
16777215   $B$35
16777215   $C$35
65535   $D$35
16777215   $E$35
5296274   $F$35
16777215   $G$35
16777215   $H$35
16777215   $A$36
16777215   $B$36
16777215   $C$36
65535   $D$36
16777215   $E$36
65535   $F$36
16777215   $G$36
16777215   $H$36
16777215   $A$37
16777215   $B$37
16777215   $C$37
5296274   $D$37
16777215   $E$37
5296274   $F$37
16777215   $G$37
16777215   $H$37
16777215   $A$38
16777215   $B$38
16777215   $C$38
65535   $D$38
16777215   $E$38
5296274   $F$38
16777215   $G$38
16777215   $H$38
As you can see, that is not showing the interior color of 15261367
For that reason, I expect your macro is erroring because it is not always finding 15261367
( Note – at cell E17 its showing 15261110 )

_... I need to continue in next post because of the post size limit…..
In the next post is the same output again , in one of my Excel 2010
Last edited by Doc.AElstein on 07 Apr 2021, 09:46, edited 4 times in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

_… continued from last post…

Code: Select all

 16777215   $B$14
16777215   $C$14
16777215   $D$14
16777215   $E$14
16777215   $F$14
16777215   $G$14
16777215   $H$14
16777215   $A$15
16777215   $B$15
16777215   $C$15
16777215   $D$15
16777215   $E$15
16777215   $F$15
16777215   $G$15
16777215   $H$15
16777215   $A$16
16777215   $B$16
16777215   $C$16
16777215   $D$16
16777215   $E$16
16777215   $F$16
16777215   $G$16
16777215   $H$16
16777215   $A$17
16777215   $B$17
16777215   $C$17
16777215   $D$17
****15261367  ******   $E$17
16777215   $F$17
16777215   $G$17
16777215   $H$17
16777215   $A$18
16777215   $B$18
16777215   $C$18
16777215   $D$18
16777215   $E$18
16777215   $F$18
16777215   $G$18
16777215   $H$18
16777215   $A$19
16777215   $B$19
16777215   $C$19
16777215   $D$19
16777215   $E$19
16777215   $F$19
16777215   $G$19
16777215   $H$19
16777215   $A$20
16777215   $B$20
16777215   $C$20
16777215   $D$20
16777215   $E$20
16777215   $F$20
16777215   $G$20
16777215   $H$20
16777215   $A$21
16777215   $B$21
16777215   $C$21
16777215   $D$21
16777215   $E$21
16777215   $F$21
16777215   $G$21
16777215   $H$21
16777215   $A$22
16777215   $B$22
16777215   $C$22
16777215   $D$22
16777215   $E$22
16777215   $F$22
16777215   $G$22
16777215   $H$22
16777215   $A$23
16777215   $B$23
16777215   $C$23
16777215   $D$23
16777215   $E$23
16777215   $F$23
16777215   $G$23
16777215   $H$23
16777215   $A$24
16777215   $B$24
16777215   $C$24
16777215   $D$24
16777215   $E$24
16777215   $F$24
16777215   $G$24
16777215   $H$24
16777215   $A$25
16777215   $B$25
16777215   $C$25
16777215   $D$25
16777215   $E$25
16777215   $F$25
16777215   $G$25
16777215   $H$25
16777215   $A$26
16777215   $B$26
16777215   $C$26
16777215   $D$26
16777215   $E$26
16777215   $F$26
16777215   $G$26
16777215   $H$26
16777215   $A$27
16777215   $B$27
16777215   $C$27
16777215   $D$27
16777215   $E$27
16777215   $F$27
16777215   $G$27
16777215   $H$27
16777215   $A$28
16777215   $B$28
16777215   $C$28
16777215   $D$28
16777215   $E$28
16777215   $F$28
16777215   $G$28
16777215   $H$28
16777215   $A$29
16777215   $B$29
16777215   $C$29
16777215   $D$29
16777215   $E$29
16777215   $F$29
16777215   $G$29
16777215   $H$29
16777215   $A$30
16777215   $B$30
16777215   $C$30
16777215   $D$30
16777215   $E$30
16777215   $F$30
16777215   $G$30
16777215   $H$30
16777215   $A$31
16777215   $B$31
16777215   $C$31
16777215   $D$31
16777215   $E$31
16777215   $F$31
16777215   $G$31
16777215   $H$31
16777215   $A$32
16777215   $B$32
16777215   $C$32
16777215   $D$32
16777215   $E$32
16777215   $F$32
16777215   $G$32
16777215   $H$32
16777215   $A$33
16777215   $B$33
16777215   $C$33
16777215   $D$33
16777215   $E$33
16777215   $F$33
16777215   $G$33
16777215   $H$33
16777215   $A$34
16777215   $B$34
16777215   $C$34
15773696   $D$34
16777215   $E$34
15773696   $F$34
16777215   $G$34
16777215   $H$34
16777215   $A$35
16777215   $B$35
16777215   $C$35
65535   $D$35
16777215   $E$35
5296274   $F$35
16777215   $G$35
16777215   $H$35
16777215   $A$36
16777215   $B$36
16777215   $C$36
65535   $D$36
16777215   $E$36
65535   $F$36
16777215   $G$36
16777215   $H$36
16777215   $A$37
16777215   $B$37
16777215   $C$37
5296274   $D$37
16777215   $E$37
5296274   $F$37
16777215   $G$37
16777215   $H$37
16777215   $A$38
16777215   $B$38
16777215   $C$38
65535   $D$38
16777215   $E$38
5296274   $F$38
16777215   $G$38
16777215   $H$38

In that listing above, you see you have found 15261367 ( at cell E17 ) . In this Excel 2010 of mine which I used, your macro does not error

Maybe to solve your problem you need to run my test macro in a few different Excel versions and see what color index is being found in E17, then modify your macro somehow to work on either
the interior color of 15261367
or
15261110
or ….. etc

I will check later for you on some of my other excel versions , including other 2007 and 2010 computers , and let you know what results I get

I don't understand much about colors and formats in Excel, but possibly some shades of color will have slightly different "numbers" in different Excel versions ? -
Alan
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
rory
5StarLounger
Posts: 817
Joined: 24 Jan 2010, 15:56

Re: Findformat interior color doesn't work on excel 2010

Post by rory »

Couple of points:

1. Your code should never assume that a Find will work. Always test if the found cell is Nothing before you try and use it.
2. In all versions (currently), and arguments that you don't specify for Find will retain their last used values (either in code or in the UI), which can also affect whether your find works. It is generally safer to specify them all with the values you need.
Regards,
Rory

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

Thanks a lot for replies.
As for the point of "Your code should never assume that a Find will work", yes as there must be be at least a cell with that color in column E.
And the code should detect the last cell with that color. The original code is already working in office 365 but not on office 2010.

@Alan "I don't understand much about colors and formats in Excel, but possibly some shades of color will have slightly different "numbers" in different Excel versions ? -" >> is there any workaround to solve the problem of the difference to be suitable working on any version?

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Hello again..
I was posting this just as you replied Yasser., so I will post it first then look again at your last reply…

I took a look on some other Excel versions and different computers, operating systems etc…
( https://excelfox.com/forum/showthread.p ... #post15501
https://excelfox.com/forum/showthread.p ... #post15502
https://excelfox.com/forum/showthread.p ... #post15503
)

2003 ( .xls saved file version )
Very consistently I get 16764057 for the interior color of cell E17
( So your macro, Yasser, won’t work, because it fails to find 15261367 )

2007
.xlsb original file

Occasionally your .xlsb file will not open unless I let Excel do a recovery/ repair that it offers. When this happens there is no interior color shown anywhere so all interior colors come out at 16777215
More often your .xlsb original file does open OK. Then the interior color of cell E17 is seen as 15261110
( So your macro won’t work, because it fails to find 15261367 )

2007
.xls saved file version

I never have any problem opening this file version in any Excel 2007.
The interior color of cell E17 is seen as 15261110
( So your macro won’t work, because it fails to find 15261367 )

2010
.xlsb original file

**Occasionally your .xlsb file will not open unless I let Excel do a recovery/ repair that it offers. When this happens there is no interior color shown anywhere so all interior colors come out at 16777215
More often your .xlsb original file does open OK. Then the interior color of cell E17 is seen as 15261367
So for me, so far, your macro always works in Excel 2010 if the file opens OK, ( which it mostly does, but not always**).

2010
.xls saved file version

So far this file opens in all my Excel 2010, and sees cell E17 interior color as 16777215, so your macro always works

_.______

So , it looks initially as you should be looking for any one of these three interior colors:
16777215 Or 15261110 Or 16764057
I would probably go along with something like rory said, - what she said about not using .Find things unless you are 100% sure of finding them.
Maybe better still forget all about .FindFormat and .Find, and just write a simple macro that checks cells for either of those interior colors.
( The only advantage of using .Find that I have ever experienced is that it can be very efficient/ fast.
Unless you are looking for super performance I would forget about .Find stuff and keep it simple, such as a simple For Each cel type loop checking the interior color )

Alan
_.______

P.S.
_1 ( Note that result of the interior color I get for the .xls file corresponds to that which I get for a working .xlsb file in that Excel version. - I find that a bit strange. - Even though it’s a .xls file, it seems to have information to tell it to give different values of interior color for cell E17 in the different Excel versions. Weird )

_2 ( I only just now can get on 2003 2007 and 2010. - I will make a note to check on a 2013 and 365 ( insider fast ) that I will be on next week, but I expect they will all work after seeing/ .Finding the 15261367 – If I get any different strange results I will write back ).

_3 If I get any different results for the interior color on any versions I will update here and at those links..

_4
rory wrote:
07 Apr 2021, 08:53
... arguments that you don't specify for Find will retain their last used values (either in code or in the UI), which can also affect whether your find works....
Interesting, I didn’t know that. I may need to re think some old codings of mine now.. :(
So it’s another vote for being more explicit and including all arguments, - and better still, used named ones as well just to make it really worthwhile and pretty. :)
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

interior color number may be different in different Excel versions

Post by Doc.AElstein »

YasserKhalil wrote:
07 Apr 2021, 11:01
The original code is already working in office 365 but not on office 2010….
??? That is strange: As you see from my last post, so far your macro is mostly working in all my Excel 2010s
It trips up in Excel 2003 and Excel 2007 only so far.
( So far what i see for your light blue cell, E17 -
2010 - .Interior.Color = 15261367
2003 .Interior.Color = 16764057
2007 .Interior.Color = 15261110
)
_.-______
YasserKhalil wrote:
07 Apr 2021, 11:01
As for the point of "Your code should never assume that a Find will work", yes as there must be be at least a cell with that color in column E.
And the code should detect the last cell with that color. The original code is already working in office 365 but not on office 2010.

@Alan "I don't understand much about colors and formats in Excel, but possibly some shades of color will have slightly different "numbers" in different Excel versions ? -" >> is there any workaround to solve the problem of the difference to be suitable working on any version?
I don’t understand enough about how .FindFormat works, so I don’t know if your original macro could be easily adapted to take the three different numbers
I suppose the only simple answer I have is to do a simple thing like looping through the cells, checking for either of the three different numbers in the cells interior color.
It is not 100% clear to me from your macro or workbook, exactly what and where and how you are wanting to do things, so I cant suggest a specific macro.

Maybe something of this form, but you may need to tweak it a bit, if I have not guessed correctly what you are wanting to do
What I am doing is looping backwards the columns in the last row , then up a row, and going back along the columns, then up a row, and going back along the columns, then up a row, and going back along the columns, …. etc..
At each cell in the Used Range, I am doing a simple check for either of the three colors interior numbers - ( those are the numbers that so far I have seen for the light blue interior color you have in cell E17 in your original uploaded file )

Code: Select all

Sub Colored_Cell() '  https://eileenslounge.com/viewtopic.php?f=30&t=36380
    Dim LastTableCell, LastColoredCell, Ws As Worksheet, lr8 As Long
    Set Ws = ThisWorkbook.Sheets("DATA")
    lr8 = Ws.ListObjects("Table1").Range.Columns(8).Cells.Find("*", SearchDirection:=xlPrevious).Row
Dim Cnt As Long, UsdRng As Range: Set UsdRng = Ws.UsedRange
    For Cnt = Ws.UsedRange.Cells.Count To 1 Step -1   '                                  Excel 2003                                 Excel 2007
        If UsdRng.Item(Cnt).Interior.Color = 15261367 Or UsdRng.Item(Cnt).Interior.Color = 16764057 Or UsdRng.Item(Cnt).Interior.Color = 15261110 Then
         Let LastColoredCell = UsdRng.Item(Cnt).Address
        Else
         ' Do Nothing
        End If
    Next Cnt
'    Application.FindFormat.Clear
'    Application.FindFormat.Interior.Color = 15261367
'
'    LastColoredCell = Ws.UsedRange.Find("", , , , , 2, , , True).Offset(, -3).Address
'    '   What , After , LookIn  , LookAt , SearchOrder  ,  SearchDirection  , MatchCase,  MatchByte  , SearchFormet
'    '   ""   ,       ,         ,        ,              ,      2            ,          ,             , True
'    '   ""   ,       ,         ,        ,              ,    xlPrevious     ,          ,             , True
 Let LastTableCell = Ws.Range("i" & lr8).Address
 Let Ws.PageSetup.PrintArea = Ws.Range(LastColoredCell, LastTableCell).Address
 Application.FindFormat.Clear
End Sub
Alan

_._______

P.S: It would be interesting to see what you ( or anyone else ) gets for Interior color results from using my test macro below, Sub WhatInteriorColor() , which I include here with a modification so as to be sure you know what version of Excel you are using. ( That macro, Public Function ExcelVersion() may not tell you accurately what newer version you have, but should distinguish correctly between the earlier versions )

Code: Select all

Sub WhatInteriorColor() '   https://eileenslounge.com/viewtopic.php?p=282274#p282274
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Sheets("DATA")
Debug.Print ExcelVersion
Dim RngTemp As Range
    For Each RngTemp In Ws.UsedRange
        If RngTemp.Interior.Color = 15261367 Then
        Debug.Print "****  " & RngTemp.Interior.Color & "  ******   " & RngTemp.AddressLocal
        Else
        Debug.Print RngTemp.Interior.Color & "   " & RngTemp.AddressLocal
        End If
    Next RngTemp
End Sub
' From Rory's Tools    '     https://web.archive.org/web/20140810122011/http://excelmatters.com/excel-forums/      https://web.archive.org/web/20140803020021/http://excelmatters.com/wp-content/uploads/2014/07/Forum-Tools.xlam
Public Function ExcelVersion() As String
    Dim temp                  As String

    'On Error Resume Next
#If Mac Then
    Select Case CLng(Val(Application.Version))
        Case 11: temp = "Excel 2004"
        Case 12: temp = "Excel 2008" ' this should NEVER happen!
        Case 14: temp = "Excel 2011"
        Case 15: temp = "Excel 2016 (Mac)"
        Case Else: temp = "Unknown"
    End Select
#Else
    Select Case CLng(Val(Application.Version))
        Case 9: temp = "Excel 2000"
        Case 10: temp = "Excel 2002"
        Case 11: temp = "Excel 2003"
        Case 12: temp = "Excel 2007"
        Case 14: temp = "Excel 2010"
        Case 15: temp = "Excel 2013"
        Case 16: temp = "Excel 2016 (Windows)"
        
        Case Else: temp = "Unknown"
    End Select
#End If
#If Win64 Then
    temp = temp & " 64 bit"
#Else
    temp = temp & " 32 bit"
#End If

    ExcelVersion = temp
End Function
_.____
P.S.2 Possibly another solution would be for you to use more standard interior colors, like for example , .Interior.Colorindex= 42 , could be a good answer.....
That is a nice pretty light blue
I would take a guess that Excel is less likely to change that between versions
Last edited by Doc.AElstein on 07 Apr 2021, 13:19, edited 5 times in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

Thanks a lot Mr. Alan
As for the office 365 I tested the code (WhatInteriorColor) and the results are in a text file
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Thanks, I have added it to my lists ( As expected its showing 15261367 for cell E17 .InteriorColor )
If you have time, can you run my modified macro here at the end of this post on the Office 10 that is giving you problems. – That modified macro will also check your Excel version
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

As for the trick of looping worked well with me and I did that yesterday. But I have a 17000 rows in the original file and looping would take time for such a task.
By the way, these are the results of 2010 (xp operating system)
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Could you try again using this macro on your 2010
( Remember to copy also the function
Public Function ExcelVersion() )

Code: Select all

Sub WhatInteriorColor() '   https://eileenslounge.com/viewtopic.php?p=282283#p282283
Dim Ws As Worksheet: Set Ws = ThisWorkbook.Sheets("DATA")
Debug.Print ExcelVersion
Dim RngTemp As Range
    For Each RngTemp In Ws.UsedRange
        If RngTemp.Interior.Color = 15261367 Then
        Debug.Print "****  " & RngTemp.Interior.Color & "  ******   " & RngTemp.AddressLocal
        Else
        Debug.Print RngTemp.Interior.Color & "   " & RngTemp.AddressLocal
        End If
    Next RngTemp
End Sub
' From Rory's Tools    '     https://web.archive.org/web/20140810122011/http://excelmatters.com/excel-forums/      https://web.archive.org/web/20140803020021/http://excelmatters.com/wp-content/uploads/2014/07/Forum-Tools.xlam
Public Function ExcelVersion() As String
    Dim temp                  As String

    'On Error Resume Next
#If Mac Then
    Select Case CLng(Val(Application.Version))
        Case 11: temp = "Excel 2004"
        Case 12: temp = "Excel 2008" ' this should NEVER happen!
        Case 14: temp = "Excel 2011"
        Case 15: temp = "Excel 2016 (Mac)"
        Case Else: temp = "Unknown"
    End Select
#Else
    Select Case CLng(Val(Application.Version))
        Case 9: temp = "Excel 2000"
        Case 10: temp = "Excel 2002"
        Case 11: temp = "Excel 2003"
        Case 12: temp = "Excel 2007"
        Case 14: temp = "Excel 2010"
        Case 15: temp = "Excel 2013"
        Case 16: temp = "Excel 2016 (Windows)"
        
        Case Else: temp = "Unknown"
    End Select
#End If
#If Win64 Then
    temp = temp & " 64 bit"
#Else
    temp = temp & " 32 bit"
#End If

    ExcelVersion = temp
End Function
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

Here's the file (results for 2010 32 Bit)
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Ahh …., OK, I see a small problem and error in my thinking… .
My stupidity has confused the situation a little, sorry about that…

The Immediate window is not showing all the data because it is limited in the size of data it excepts, so it chops off the first few lines.
Can you try this version. ( It will make the text file for you in the same folder as where the Excel file is )

Code: Select all

Sub WhatInteriorColorToTxtFile() '   https://eileenslounge.com/viewtopic.php?p=282274#p282274
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("DATA")
Dim TotalFile As String
 Let TotalFile = ExcelVersion & vbCrLf
Dim RngTemp As Range
    For Each RngTemp In ws.UsedRange
        If RngTemp.Interior.Color = 15261367 Then
         Let TotalFile = TotalFile & "****  " & RngTemp.Interior.Color & "  ******   " & RngTemp.AddressLocal & vbCr & vbLf
        Else
         Let TotalFile = TotalFile & RngTemp.Interior.Color & "     " & RngTemp.AddressLocal & vbCr & vbLf
        End If
    Next RngTemp
Rem    Make text file
Dim FileNum2 As Long: Let FileNum2 = FreeFile(0)                                  ' https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/freefile-function
Dim PathAndFileName2 As String
 Let PathAndFileName2 = ThisWorkbook.Path & "\" & "Results For  " & Replace(ThisWorkbook.Name, ".", " ") & "  Using " & ExcelVersion & ".txt" ' ' CHANGE TO SUIT  ' Will be made if not there
 Open PathAndFileName2 For Output As #FileNum2
 Print #FileNum2, TotalFile ' write out entire text file
 Close #FileNum2

End Sub
'
' ' From Rory's Tools    '     https://web.archive.org/web/20140810122011/http://excelmatters.com/excel-forums/      https://web.archive.org/web/20140803020021/http://excelmatters.com/wp-content/uploads/2014/07/Forum-Tools.xlam
Public Function ExcelVersion() As String
    Dim temp                  As String

    'On Error Resume Next
#If Mac Then
    Select Case CLng(Val(Application.Version))
        Case 11: temp = "Excel 2004"
        Case 12: temp = "Excel 2008" ' this should NEVER happen!
        Case 14: temp = "Excel 2011"
        Case 15: temp = "Excel 2016 (Mac)"
        Case Else: temp = "Unknown"
    End Select
#Else
    Select Case CLng(Val(Application.Version))
        Case 9: temp = "Excel 2000"
        Case 10: temp = "Excel 2002"
        Case 11: temp = "Excel 2003"
        Case 12: temp = "Excel 2007"
        Case 14: temp = "Excel 2010"
        Case 15: temp = "Excel 2013"
        Case 16: temp = "Excel 2016 (Windows)"
        
        Case Else: temp = "Unknown"
    End Select
#End If
#If Win64 Then
    temp = temp & " 64 bit"
#Else
    temp = temp & " 32 bit"
#End If

    ExcelVersion = temp
End Function
Last edited by Doc.AElstein on 07 Apr 2021, 15:01, edited 1 time in total.
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

I am using office 365 and one of my friends is using office 2010 (on XP)
Here's my results for office 365
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

OK, those results make sense, here is the first few lines of the text file.

Code: Select all

Excel 2016 (Windows) 32 bit
16777215     $A$1
16777215     $B$1
16777215     $C$1
16777215     $D$1
16777215     $E$1
16777215     $F$1
16777215     $G$1
16777215     $H$1
16777215     $A$2
16777215     $B$2
16777215     $C$2
16777215     $D$2
16777215     $E$2
16777215     $F$2
16777215     $G$2
16777215     $H$2
16777215     $A$3
16777215     $B$3
16777215     $C$3
16777215     $D$3
16777215     $E$3
16777215     $F$3
16777215     $G$3
16777215     $H$3
16777215     $A$4
16777215     $B$4
16777215     $C$4
16777215     $D$4
****  15261367  ******   $E$4
16777215     $F$4
16777215     $G$4
16777215     $H$4
16777215     $A$5
16777215     $B$5
16777215     $C$5
16777215     $D$5
16777215     $E$5
16777215     $F$5
16777215     $G$5
16777215     $H$5
16777215     $A$6
16777215     $B$6
16777215     $C$6
16777215     $D$6
16777215     $E$6
16777215     $F$6
16777215     $G$6
16777215     $H$6
16777215     $A$7
16777215     $B$7
16777215     $C$7
16777215     $D$7
16777215     $E$7
16777215     $F$7
16777215     $G$7
16777215     $H$7
16777215     $A$8
16777215     $B$8
16777215     $C$8
16777215     $D$8
16777215     $E$8
16777215     $F$8
16777215     $G$8
16777215     $H$8
16777215     $A$9
16777215     $B$9
16777215     $C$9
16777215     $D$9
16777215     $E$9
16777215     $F$9
16777215     $G$9
16777215     $H$9
16777215     $A$10
16777215     $B$10
16777215     $C$10
16777215     $D$10
16777215     $E$10
16777215     $F$10
16777215     $G$10
16777215     $H$10
16777215     $A$11
16777215     $B$11
16777215     $C$11
16777215     $D$11
16777215     $E$11
16777215     $F$11
16777215     $G$11
16777215     $H$11
16777215     $A$12
16777215     $B$12
16777215     $C$12
16777215     $D$12
16777215     $E$12
16777215     $F$12
16777215     $G$12
16777215     $H$12
16777215     $A$13
16777215     $B$13
16777215     $C$13
16777215     $D$13
16777215     $E$13
16777215     $F$13
16777215     $G$13
16777215     $H$13
16777215     $A$14
16777215     $B$14
16777215     $C$14
16777215     $D$14
16777215     $E$14
16777215     $F$14
16777215     $G$14
16777215     $H$14
16777215     $A$15
16777215     $B$15
16777215     $C$15
16777215     $D$15
16777215     $E$15
16777215     $F$15
16777215     $G$15
16777215     $H$15
16777215     $A$16
16777215     $B$16
16777215     $C$16
16777215     $D$16
16777215     $E$16
16777215     $F$16
16777215     $G$16
16777215     $H$16
16777215     $A$17
16777215     $B$17
16777215     $C$17
16777215     $D$17
****  15261367  ******   $E$17
16777215     $F$17
16777215     $G$17
16777215     $H$17
As I expected, the .Interior.Color for call E17 is 15261367

( I think possibly Excel has the same version number for Excel 2016 2019 and 365 , so that's why in the case of this newer version the version given is not quite correct. Possibly someone like Rory might have some idea how to determine the exact Office version for newer versions. But that is a side issue, and is less importaqnt for your issue which appears to be with earlier versions.
More intersting is what results you get for your friends 2010 )
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also

hassona229
NewLounger
Posts: 1
Joined: 05 Oct 2019, 00:54

Re: Findformat interior color doesn't work on excel 2010

Post by hassona229 »

I am using office 2010 (on XP)
Here's my results for office 2010
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78478
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Findformat interior color doesn't work on excel 2010

Post by HansV »

Excel 2016, 2019 and 365 all have the internal version number 16.0, and they share the same core, so they will most probably handle colors the same way. There is no 'native' way to distinguish between these versions in VBA, it requires running an external script.
Best wishes,
Hans

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Findformat interior color doesn't work on excel 2010

Post by YasserKhalil »

Thanks a lot, Mr. Hans for the reply and for the information.
Here are the results for 2010 Mr. Alan
You do not have the required permissions to view the files attached to this post.

User avatar
Doc.AElstein
BronzeLounger
Posts: 1499
Joined: 28 Feb 2015, 13:11
Location: Hof, Bayern, Germany

Re: Findformat interior color doesn't work on excel 2010

Post by Doc.AElstein »

Thanks hassona229 for your file, that’s very useful to get some more results to check against. ( and Welcome to posting at Eileen’s lounge ! )

Thanks Yasser for the files
_.____

If we compare those files, along with one of my XP 2010 machines, then we see that the results all tie up with each other, and also tie up with my results for Vista and Windows 7 for Office 2010

All are giving me for cell E17 on the original xlsb test file the .Interior.Color of 15261367

_._____

So it’s currently a bit puzzling why Yasser’s original macro is not working in Office 2010, because so far my results for a different .Interior.Color are only occurring at Office 2007 and 2003

Having said that, I am experiencing some peculiar inconsistent results generally with some experiments that I am doing with .Find and .FindFormat
So there might be some quirks or bugs somewhere.
I will post back if I have anything more useful to add.
_._____
HansV wrote:
07 Apr 2021, 15:10
Excel 2016, 2019 and 365 all have the internal version number 16.0, and they share the same core, so they will most probably handle colors the same way. There is no 'native' way to distinguish between these versions in VBA, it requires running an external script.
I thought there was a possibility that might be the case, thanks for the clarity, Hans
I am having difficulty logging in with this account just now.
You can find me at DocAElstein also