Results 1 to 10 of 10

Thread: Color cielab to rgb

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Color cielab to rgb

    Hi everybody,

    I need the help to close a problem nearly solved.

    I have a code that convert color CIELAB to RGB and show the color in one cell of Excell.

    Until here, the code works but pressing one boton to change the color of only one cell.

    I would like to know if it is possible to convert in one function or at least in one routine that can change several cells, not one by one.

    I attached the example with some comments to understand what I need.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Color cielab to rgb

    you can try like
    Code:
    Sub LabtoCell(rng)
    For Each cel In rng
        CIELABtoXYZ cel.Offset(, -5), cel.Offset(, -4), cel.Offset(, -3)
        XYZtoRGB X, Y, Z
        Debug.Print X, Y, Z, R, G, b
        cel.Interior.Color = RGB(R, G, b)
    Next
    End Sub
    call like LabtoCell Range("g11:g15")
    change the cel offsets to suit the column being changed, or pass an additional parameter, the colours looked like only 2 different colours so i printed the values, as below, to make sure i was not getting any values that were not changing

    73.0869665227941 78.5097284012342 53.4468722746728 242.862445290982 229.411580904281 178.050642184066
    75.3210749848906 82.9944316014474 60.2718206464701 239.169921430019 237.636558057976 189.139075380019
    89.2158188162545 97.4665288194555 66.3505541457003 261.833338349867 254.033627647506 196.0278112245
    75.5960197709468 78.5097284012342 57.6160520272094 249.961569969439 226.475614577481 185.98777123631
    67.4648564810078 73.4839141796604 46.6212846030531 234.179762550014 223.825332370949 165.829085011217
    Last edited by westconn1; Jan 13th, 2018 at 06:48 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Re: Color cielab to rgb

    Hi Pete,

    I am not one expert in VB.

    Could you modify the example and attach it?

    Thanks in advance.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Color cielab to rgb

    just add the sub as posted to your existing code module, you can call it from any other procedure, or a menu button, as you need to somehow specify the range of cells to update, you could use an inputbox to get the user to input the range

    if you want to colour the column E the offsets should be -3, -2, -1, as i coloured column g the offsets were 2 more (negative)

    i edited the code a bit to make it easy to adjust the column, using an additional parameter
    Code:
    Sub LabtoCell(rng, col)
    For Each cel In rng
        CIELABtoXYZ cel.Offset(, col), cel.Offset(, col + 1), cel.Offset(, col + 2)
        XYZtoRGB X, Y, Z
        Debug.Print X, Y, Z, R, G, b
        cel.Interior.Color = RGB(R, G, b)
    Next
    End Sub
    to match the original sample value for col would be -5 (no of columns to first column of colour data), for column E col would be -3, or to colour column A col would be 1, for existing data columns, call like
    Code:
    LabtoCell range("E11:E15", -3)
    as it was a bit difficult to guess how you actually wanted to implement the code, i tried to make it universal, not specific to any range of columns, if your use of columns is constant the code in the first sample may be enough

    note i did not in any way test if the results from the calculations were correct, i just made a procedure to apply the existing calculations to a generic range of cells on the same row as the input data
    Last edited by westconn1; Jan 13th, 2018 at 05:22 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Re: Color cielab to rgb

    Hi Pete,

    Sorry, but I repeat "I have not many knownledge of VB".

    My idea is to change the specific range E11:E15.

    Could you change the example and hold it?

    I tried to do what you said but without succesfull.

    Thanks in advance and for your patient.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Color cielab to rgb

    Sorry, but I repeat "I have not many knownledge of VB".
    i am not sure that i understand what you are having problem with, you have the required code, which is tested and works as requested

    i will request this thread is moved to the correct forum, someone else there may be able to give you more assistance
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Re: Color cielab to rgb

    Hi Pete:

    Only if you could attach the excell file with the solution, I will close this point.

    I don´t know what I am doing wrong, but the code for myself doesn´t work.

    Best regards,

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Color cielab to rgb

    you still have not specified how you want to start the code
    do you want to click a button or what?

    i can not demonstrate a ribbon button as my excel is pre-ribbon
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2018
    Posts
    5

    Re: Color cielab to rgb

    Hi,

    Sorry for not explaining well.

    Is it possible one code that in case it find values in column B,C and D show the color in column E?

    Or it is neccessary always one boton to actionate the colors?

    See the sample I attach in the first email (B11-E15).

    Best regards,

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Color cielab to rgb

    the code i posted in #2 will change the colour of all the cells in the specified range, from one button (or whatever you want to initiate the action)

    Code:
    Sub LabtoCell(rng)
    For Each cel In rng
        CIELABtoXYZ cel.Offset(, -3), cel.Offset(, -2), cel.Offset(, -1)
        XYZtoRGB X, Y, Z
        cel.Interior.Color = RGB(R, G, b)
    Next
    End Sub
    the code here is specific to changing the colour of column E, from values in B, C and D

    Code:
    Sub CIELABtoRGB()
    LabtoCell range("E11:E15")
    '--
    '1º) Convertimos CIELAB A XYZ
    'CIELABtoXYZ [B3], [C3], [D3]
    '--
    '2º) Convertimos XYZ a RGB
    'XYZtoRGB X, Y, Z
    '[F3] = R: [G3] = G: [H3] = b
    '--
    '3º) Coloreamos
    '[J2].Interior.Color = RGB(R, G, b)
    End Sub
    if you add the top procedure and make the above changes to your existing code, the existing button at E2 will now work to change the colour of all the cells E11 to E15

    i initially tried to make the code generic, so that you could adjust the position of the coloured cells, but it should have been more basic

    you should look at doing a course to learn the basics of implementing macros (vba code procedures), the existing code in your workbook makes it appear that you are more advanced, or at least would know how to run the macros
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width