Consulting

Results 1 to 13 of 13

Thread: Need help restructuring code tohighlight numerical data w/o special characters please

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location

    Need help restructuring code tohighlight numerical data w/o special characters please

    I have numerical data without special characters in column AG. this data will match data in the Range of AI2 through AP71.

    I need the code "color cells in range or sheet" to be modified for this where the current data is located.
    Also the current code looks for, for example 1-10-E, but it needs to be changed to look for just numerical data with out special characters or Alpha characters.

    Also it currently colors the data it finds in the range AI2:AP71 to red.

    is it possible to have each number to be colored a color specified for that number? the numbers are 1 to 7.

    I had uploaded and example as well as in the example the colors assinged to these numbers.

    Any help with this would be greatly appreciated.

    Thank you very much in advance!!!
    Attached Files Attached Files
    Last edited by estatefinds; 07-20-2016 at 06:49 AM.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I don't know if you mean match AG to AI:AP in the same row or each AG value in all of AI to AP. To mark the colors, I don't know if you want a match and color just the found cell or the row AI4:AP4 for match to AG4.

    I don't see any markup as red when I ran your macro. Maybe showing in a file the final result expected for just a few rows manually marked would be sufficient.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Sub blah2()
    Colours = Array(65535, 65280, 49407, 13995347, 6684927, 255, 6684774)
    For Each cll In Range("AI2:AP71").Cells
      cll.Interior.Color = xlNone
      If IsNumeric(cll.Value) Then
        If cll.Value > 0 And cll.Value < 8 Then cll.Interior.Color = Colours(cll.Value - 1)
      End If
    Next cll
    End Sub
    Last edited by p45cal; 07-20-2016 at 10:56 AM. Reason: adjusted code
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    Ok so I have data in column AG this is just the occurence of the data in the column AE that consist of numbers 1 through 7. this is for me to review and not necessary for macro.
    (the data that should be used is the data AU3 to AV9 that shows colors to be used to color data found in the AI2 to AP71.)

    Now if you look at the data in AI2 through AP71 some you ll see in various spots single numbers through 1 to 7.

    now I need macro in which I press ALT F8 and it will color the numbers 1 through 7 as each number are assinged a color as seen in the example. so for example the number 2 in AI 2 will be colored and any other found in the range of AI2 to AP71, and so on, the colors I would like assinged are in the range AU3to AV9.

    Also the reason it didnt color red is because the current macro only recognizes the 1-10-E format and not the single number format for example "1" or "2" or "3" or "4" or "5" or "6" or "7". so for example the number "2" that is colored in cell AI2 and so should all the other ones as well in the range AI2 to AP71 if it is there.

    so each number assigned a color, and when the macro is modified it will color the numbers found in the range AI2 to AP71 any of the 1 through 7. so all the ones that appear in the in the range will be colored the assinged color. all the of the 2's in the range found will be the color assigned that are found in the range, an so on.

    When you open work book slide to the left of it and youll see the example of what origianl code id in regards to coloring red.

    Thank you
    Attached Files Attached Files

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    see adjusted code in msg#3
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    Yes exactly!!! Thank you very Much!!!!

    You do Excellent Work!!!

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Or if you want to be able to change the colours, then adjust them in the range AV3:AV9 and run this:
    Sub blah3()
    For Each cll In Range("AI2:AP71").Cells
      cll.Interior.Color = xlNone
      If IsNumeric(cll.Value) Then
        If cll.Value > 0 And cll.Value < 8 Then cll.Interior.Color = Range("Av2").Offset(cll.Value).Interior.Color
      End If
    Next cll
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    Excellent!!! Thganks Again!!!

  9. #9
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    I ran into a problem when I deleted data in th range AI2 to AP71 And ran the so the numbers appeared and ran the the BLAH2 i got an error run time error?


    I figured it out thanks Again!!!

  10. #10
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    Ok so I ran new data and ran the BLAH 2 and gpt an error message, can you help me with this? Im not sure why this is happening. I see the code when i open devoloper but is there something that is in the AI2 cell that im removing/ when i place new data?

    wheni click Debug i get this

    cll.Interior.Color = Colours(cll.Value - 1) Else

    when i copy and paste the origianl data to run macro it works, but when I edit data by replacing with new data before runing the BLAH2 is get the run time error

  11. #11
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    ok, I think I figured it out! I dont change that data, i just use the other macros to run and the data will change then run BLAH 2. looks like all working well.
    Thanks gain!

  12. #12
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    This is a guess: you may have values >0 but less than 1?
    Try changing to:
    If cll.Value >= 1 And cll.Value <= 7 Then cll.Interior.Color = Colours(cll.Value - 1)
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  13. #13
    VBAX Mentor
    Joined
    Feb 2016
    Posts
    382
    Location
    I'll give it a shot thanks again!!

Posting Permissions

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