कॉलम सेल नंबरों के आधार पर कई पंक्तियों को कैसे उजागर किया जाए?


0

मैं स्वचालित रूप से एक कॉलम में संख्याओं के समूह के आधार पर कई पंक्तियों को उजागर करना चाहता हूं। इसलिए मेरे पास प्रत्येक अद्वितीय परिवार आईडी के लिए एक अलग पंक्ति का रंग होगा। सशर्त तैयार करने में रंग का चयन करने के लिए मैन्युअल रूप से ऐसा करने का कोई तरीका है? मेरे पास 400 परिवार और 1000+ पंक्तियाँ हैं। मदद के लिए बहुत शुक्रिया दोस्तों।

उदाहरण डेटा:

FamilyID  Stock Number     Class
1922      1361427          Box
1922      5859184          Box
1922      1422784          Box
1922      1422694          Box
2196      1336358          Circle
2196      1336244          Circle
2196      675239           Circle
2205      57813            Square
2205      863453           Square
2220      30664            Square
2220      1336732          Square
2220      22874            Square

जवाबों:


2

मान लें कि फ़ैमिलीआईडी ​​में है ColumnA, तो सशर्त स्वरूपण नियमों की एक श्रृंखला का उपयोग करें। यह निर्धारित करने के लिए कि कौन सी कोशिकाएँ फॉर्मेट करें (प्रकार = $ a2 = 1922 (पीला), = $ a2 = 2196 (हरा) इत्यादि का उपयोग करें A2और प्रत्येक में हों पूरी पंक्ति पर लागू करें।

SU528202 उदाहरण


आप सही हैं ColumnA में फैमिली आईडी है। यह समाधान वह है जिससे मैं बचने की कोशिश कर रहा था। मेरे पास 400 परिवार और 1000 पंक्तियां हैं।
user184581

3
@ user184581 यह आपके प्रश्न का उत्तर देता है जैसा आपने इसे दिया था। आप परिवारों और पंक्तियों की संख्या के बारे में विवरण शामिल करने के लिए प्रश्न को संपादित करना चाह सकते हैं ।
चार्लीआरबी

0

निम्नलिखित एक्सेल VBA रूटीन और सपोर्टिंग फंक्शंस, डेटा रेंज के पहले कॉलम में संख्याओं के आधार पर कई पंक्तियों को उजागर करने के लिए कार्यक्षमता की आपूर्ति करते हैं, एक सुविधा जो अन्यथा केवल सशर्त स्वरूपण के साथ प्राप्त करने योग्य है। किसी भी संख्या में कॉलम और पंक्तियों का चयन किया जा सकता है, हालांकि मैंने बड़े तालिकाओं पर प्रदर्शन का परीक्षण नहीं किया है।

कोड सीधा है, चयनित रेंज में कोशिकाओं के माध्यम से लूपिंग और जब प्रोग्राम आगे बढ़ता है तो पहले कॉलम में मूल्य में परिवर्तन होने पर एक नया रंग लागू होता है।

रंग चयन योजना बहुत बुनियादी है। एक्सेल (2007+) द्वारा समर्थित स्पेक्ट्रम में रंगों के समतुल्य का चयन कार्यक्रम (वर्तमान में 16) में निर्धारित अलग-अलग रंगों की संख्या के आधार पर किया जाता है और फिर डेटा तालिका में पंक्ति समूहों के लिए यादृच्छिक रूप से असाइन किया जाता है।

गहरे रंगों के लिए, कोशिकाओं में संख्या या पाठ इसके विपरीत सफेद रंग में सेट होते हैं।

दो सहायक फ़ंक्शंस मुख्य दिनचर्या को भरने वाले रंग और फ़ॉन्ट रंग कोड की आपूर्ति करते हैं।

Sub ColorSortedRange()

   ' Set the fill color of rows in a selected range based on the values
   ' in the first column of the range.

   Dim Rng As Range, Rng2 As Range
   Dim Cell_ As Range
   Dim PriorCellValue As Variant
   Dim CellColor As Long, FontColorIdx As Long
   Dim NumberOfColors As Long

   With Application
      .EnableEvents = False
      .DisplayAlerts = False
      .ScreenUpdating = False
   End With

   Set Rng = Selection
   NumberOfColors = 16                 '####### SET NUMBER OF COLORS HERE #######

   For Each Cell_ In Rng.columns(1).Cells
       If Cell_.Value <> PriorCellValue Then
           CellColor = GetColorNumber(NumberOfColors)
           FontColorIdx = GetFontColorIndex(CellColor)                      '
       End If
       Set Rng2 = Range(Cell_, Cell_.Offset(0, Rng.columns.Count - 1))
       With Rng2
           With .Interior
               .Color = CellColor
               .TintAndShade = 0.5    '####### SET TINTING AND SHADING HERE #######
           End With
           .Font.ColorIndex = FontColorIdx
       End With
       PriorCellValue = Cell_.Value
   Next

   With Application
      .EnableEvents = True
      .DisplayAlerts = True
      .ScreenUpdating = True
   End With

End Sub


Function GetColorNumber(NumberOfColors As Long) As Long

   ' Returns a color number randomly chosen from the number of
   ' colors specified. This function will not work in Excel versions
   ' prior to 2007, because of limits on the number of available
   ' colors.

   Dim Step As Long
   Dim NumberOfExcelColors As Long

   NumberOfExcelColors = 16276000 'approximately
   Step = Fix(NumberOfExcelColors / NumberOfColors)
   GetColorNumber = WorksheetFunction.RandBetween(1, NumberOfColors) * Step

   ' The Randbetween function is from the Excel Analysis ToolPak. If it is
   ' unavailable the following formula can be substituted:
   '    =INT((upperbound - lowerbound + 1) * RAND() + lowerbound)

End Function


Function GetFontColorIndex(BackgroundColor As Long) As Integer

   ' Returns color index for dark grey or white, which the function selects
   ' to contrast with the cell fill color.

   Dim R As Long, G As Long, B As Long
   Dim FontThreshold As Double
   Dim Brightness As Double


   R = BackgroundColor Mod 256
   G = (BackgroundColor \ 256) Mod 256
   B = (BackgroundColor \ 256 \ 256) Mod 256
   FontThreshold = 130

   Brightness = Sqr(R * R * 0.241 + G * G * 0.691 + B * B * 0.068)

   If Brightness < FontThreshold Then
       GetFontColorIndex = 2  'white
   Else
       GetFontColorIndex = 49 'dark (1 is black)
   End If

   ' Long decimal to RGB color conversion algorithm published by Siddharth Rout
   ' at http://social.msdn.microsoft.com/Forums/en/exceldev/thread/df8a1e1e-e974
   ' -4a9c-938a-da18ae9f5252. The formula for perceived brightness of RGB colors
   ' is available in various forms on the Internet, perhaps earliest at
   ' http://alienryderflex.com/hsp.html.

End Function

संक्षेप में बाँधना यदि कॉलम की जाँच की जानी है तो B एक सहायक स्तंभ है, कॉलम A A1: 0 A2: = MOD (OFFSET ($ A2, -1,0) + (OFFSET ($ B2, -1) में कहें) 0) <> $ B2), 2) उसके बाद सशर्त स्वरूपण सेट करें पंक्ति 1 पर किसी भी सेल का चयन करें, फिर संपूर्ण कार्यपत्रक प्रारूप, सशर्त स्वरूपण स्थिति 1 का चयन करें, सूत्र है: = $ A1 = 1
user184581

0

मैंने ऊपर कोड लिया और इसमें सुधार किया ताकि कोई मौका न हो कि यू के बाद उसी रंग के साथ सेल हो ... आनंद :)

Dim LastColor As Long

Sub ColorSortedRange()

    LastColor = GetColorNumber(5)

   ' Set the fill color of rows in a selected range based on the values
   ' in the first column of the range.

   Dim Rng As Range, Rng2 As Range
   Dim Cell_ As Range
   Dim PriorCellValue As Variant
   Dim CellColor As Long, FontColorIdx As Long
   Dim NumberOfColors As Long

   With Application
      .EnableEvents = False
      .DisplayAlerts = False
      .ScreenUpdating = False
   End With

   Set Rng = Selection
   NumberOfColors = 50                 '####### SET NUMBER OF COLORS HERE #######

   For Each Cell_ In Rng.Columns(1).Cells
       If Cell_.Value <> PriorCellValue Then
           CellColor = GetColorNumber(NumberOfColors, LastColor)
           LastColor = CellColor
           FontColorIdx = GetFontColorIndex(CellColor)                      '
       End If
       Set Rng2 = Range(Cell_, Cell_.Offset(0, Rng.Columns.Count - 1))
       With Rng2
           With .Interior
               .Color = CellColor
               .TintAndShade = 0.5    '####### SET TINTING AND SHADING HERE #######
           End With
           .Font.ColorIndex = FontColorIdx
       End With
       PriorCellValue = Cell_.Value
   Next

   With Application
      .EnableEvents = True
      .DisplayAlerts = True
      .ScreenUpdating = True
   End With

End Sub


Function GetColorNumber(NumberOfColors As Long, Optional OldColor As Long = 0) As Long

   ' Returns a color number randomly chosen from the number of
   ' colors specified. This function will not work in Excel versions
   ' prior to 2007, because of limits on the number of available
   ' colors.

   Dim Step As Long
   Dim NumberOfExcelColors As Long

   NumberOfExcelColors = 16276000 'approximately
   Step = Fix(NumberOfExcelColors / NumberOfColors)
   GetColorNumber = WorksheetFunction.RandBetween(1, NumberOfColors) * Step

   If GetColorNumber = OldColor Then
    GetColorNumber = GetColorNumber(NumberOfColors, OldColor)
   End If


   ' The Randbetween function is from the Excel Analysis ToolPak. If it is
   ' unavailable the following formula can be substituted:
   '    =INT((upperbound - lowerbound + 1) * RAND() + lowerbound)

End Function


Function GetFontColorIndex(BackgroundColor As Long) As Integer

   ' Returns color index for dark grey or white, which the function selects
   ' to contrast with the cell fill color.

   Dim R As Long, G As Long, B As Long
   Dim FontThreshold As Double
   Dim Brightness As Double


   R = BackgroundColor Mod 256
   G = (BackgroundColor \ 256) Mod 256
   B = (BackgroundColor \ 256 \ 256) Mod 256
   FontThreshold = 130

   Brightness = Sqr(R * R * 0.241 + G * G * 0.691 + B * B * 0.068)

   If Brightness < FontThreshold Then
       GetFontColorIndex = 2  'white
   Else
       GetFontColorIndex = 49 'dark (1 is black)
   End If

   ' Long decimal to RGB color conversion algorithm published by Siddharth Rout
   ' at http://social.msdn.microsoft.com/Forums/en/exceldev/thread/df8a1e1e-e974
   ' -4a9c-938a-da18ae9f5252. The formula for perceived brightness of RGB colors
   ' is available in various forms on the Internet, perhaps earliest at
   ' http://alienryderflex.com/hsp.html.

End Function
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.