I have this spreadsheet with 255 RGB Codes. I need a code to convert them to the Natural Color System (NCS).
I've tried AI solutions, which gave me VBA codes but they don't seem to work.
Example of AI generated VBA code:
When I try to use the formula they give after inserting the VBA code, it shows the error "We found a typo in your formula and tried to correct it". If you don't accept this correction, it shows the error "There's a problem with your formula", displayed in the image.
I'd like a different code to convert from RBG to NCS. But if you have any idea on how to make this VBA code work, that's great too.
Thanks!
Bianca,
BR.
I've tried AI solutions, which gave me VBA codes but they don't seem to work.
Example of AI generated VBA code:
VBA Code:
Function RGBtoNCS(r As Integer, g As Integer, b As Integer) As String
' Map basic RGB values to NCS approximations
' This is an estimated mapping, and not an exact conversion
Dim ncsColor As String
Dim minDiff As Double
Dim diff As Double
Dim i As Integer
Dim closestNCS As String
' List of common colors in NCS and their approximate RGB equivalents
Dim ncsColors(6, 3) As Variant
ncsColors(0, 0) = "NCS S 0500-N": ncsColors(0, 1) = 255: ncsColors(0, 2) = 255: ncsColors(0, 3) = 255 ' White
ncsColors(1, 0) = "NCS S 9000-N": ncsColors(1, 1) = 0: ncsColors(1, 2) = 0: ncsColors(1, 3) = 0 ' Black
ncsColors(2, 0) = "NCS S 1080-Y70R": ncsColors(2, 1) = 255: ncsColors(2, 2) = 0: ncsColors(2, 3) = 0 ' Red
ncsColors(3, 0) = "NCS S 0580-Y": ncsColors(3, 1) = 255: ncsColors(3, 2) = 255: ncsColors(3, 3) = 0 ' Yellow
ncsColors(4, 0) = "NCS S 1080-G20Y": ncsColors(4, 1) = 0: ncsColors(4, 2) = 255: ncsColors(4, 3) = 0 ' Green
ncsColors(5, 0) = "NCS S 1075-R90B": ncsColors(5, 1) = 0: ncsColors(5, 2) = 0: ncsColors(5, 3) = 255 ' Blue
' Initialize minimum difference with a large number
minDiff = 999999
' Loop through the NCS colors to find the closest match
For i = 0 To 5
diff = Sqr((r - ncsColors(i, 1)) ^ 2 + (g - ncsColors(i, 2)) ^ 2 + (b - ncsColors(i, 3)) ^ 2)
If diff < minDiff Then
minDiff = diff
closestNCS = ncsColors(i, 0)
End If
Next i
RGBtoNCS = closestNCS
End Function
When I try to use the formula they give after inserting the VBA code, it shows the error "We found a typo in your formula and tried to correct it". If you don't accept this correction, it shows the error "There's a problem with your formula", displayed in the image.
I'd like a different code to convert from RBG to NCS. But if you have any idea on how to make this VBA code work, that's great too.
Thanks!
Bianca,
BR.