Marker og kopier koden herfra Tilbage i din projektmappe taster du ALT+F11 Vælg Module i menuen Insert paste koden i vindue som fremkommer Tast ALT+Q for at returnere til arket Tast ALT+F8, marker "test" og klik Afspil/Run
Sub test() Dim Red As String Dim Green As String Dim Blue As String For Each C In Range("A1:A15") If C <> "" Then Red = Val("&H" & Mid(C, 1, 2)) 'The red value is now the long version of "00" Green = Val("&H" & Mid(C, 3, 2)) 'The red value is now the long version of "FF" Blue = Val("&H" & Mid(C, 5, 2)) 'The red value is now the long version of "1F" C.Interior.Color = RGB(Red, Green, Blue) End If Next End Sub
Public Sub Test() For Each c In Range("A1:A5") Dim A As Long If c <> "" Then A = CLng("&h" & Right(c, Len(c) - 1)) c.Interior.Color = RGB(GetRGB(A, 1), GetRGB(A, 2), GetRGB(A, 3)) End If Next End Sub
Function GetRGB(RGBval As Long, Num As Integer) As Integer ' Check if Num, RGBval are valid. If Num > 0 And Num < 4 And RGBval > -1 And RGBval < 16777216 Then GetRGB = RGBval \ 256 ^ (Num - 1) And 255 Else ' Return True (-1) if Num or RGBval are invalid. GetRGB = True End If End Function
kol = 5 ' 5 = kolonne E, ret 5 til aktuel kolonne hvor dine koder er
For t = 2 To Sheets("Ark4").Cells(65500, kol).End(xlUp).Row ' ret til aktuel ark r = "&H" & Mid(Cells(t, kol), 2, 2) g = "&H" & Mid(Cells(t, kol), 4, 2) b = "&H" & Mid(Cells(t, kol), 6, 2) Cells(t, kol).Interior.Color = RGB(r, g, b) Next
For t = 2 To Sheets("reg_db").Cells(65500, "M").End(xlUp).Row r = "&H" & Mid(Cells(t, "M"), 2, 2) g = "&H" & Mid(Cells(t, "M"), 4, 2) b = "&H" & Mid(Cells(t, "M"), 6, 2) Cells(t, "M").Interior.Color = RGB(r, g, b) Next
For t = 2 To Sheets(1).Cells(65500, "M").End(xlUp).Row If Left(Cells(t, "M"), 1) = "#" Then r = "&H" & Mid(Cells(t, "M"), 2, 2) g = "&H" & Mid(Cells(t, "M"), 4, 2) b = "&H" & Mid(Cells(t, "M"), 6, 2) Cells(t, "M").Interior.Color = RGB(r, g, b) End If Next
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.