मेरे पास एक बड़ा डेटाबेस है और मैं एक वीबीए चला रहा हूंस्क्रिप्ट कई अलग-अलग कार्यपुस्तिकाओं को बनाने के लिए जिसमें पूर्ण डेटाबेस से केवल कुछ नमूना डेटा शामिल हैं। यह अच्छी तरह से काम कर रहा है, मैं सभी प्रासंगिक प्रविष्टियों को प्राप्त करने के लिए एक मैट्रिक्स का उपयोग कर रहा हूं और फिर पूरे मैट्रिक्स को एक नई कार्यपुस्तिका की परिभाषित सीमा में चिपका रहा हूं (और एक वर्कशीट से सेल द्वारा सेल को दूसरे में कॉपी नहीं कर रहा हूं)। मेरी समस्या अब है कि मुझे सशर्त स्वरूपण के लिए दो नियम जोड़ना होगा।
मैं कुछ ढूंढ रहा हूं जैसे कि:
Application.Worksheets("Database").Cells(k, ColumnOfInterest).Select
With Selection
.FormatConditions.Delete
.FormulaR1C1 = "=RC[-3] =""A"""
.FormatConditions.Add Type:=xlExpression, Formula1:=.FormulaR1C1Local
.FormatConditions(1).Interior.ColorIndex = 6
.Formula = ""
End With
With Selection
.FormatConditions.Delete
.FormulaR1C1 = "=RC[0] ="""""
.FormatConditions.Add Type:=xlExpression, Formula1:=.FormulaR1C1Local
.FormatConditions(1).Interior.ColorIndex = 5
.Formula = ""
End With
दूसरे शब्दों में, जब उपयोगकर्ता ने "ए" चुना हैबाईं ओर तीसरा सेल, फिर प्रासंगिकता के सेल का रंग रंग सूचकांक 6 होना चाहिए, यदि ब्याज का सेल खाली है, तो रंग कोड 5 है। दुर्भाग्यवश यह कोड काम नहीं करता है और केवल सशर्त के लिए एक एकल नियम बनाता है स्वरूपण।
उत्तर:
जवाब के लिए 2 № 1.FormatConditions.Delete पिछले प्रारूप शर्त हटा देता है। यदि आप .FormatConditions को हटाते हैं। दूसरे भाग में हटाएं और बदलें .फॉर्मैट कंडीशन (1) से .ॉर्मेट कंडीशन (2) इसे काम करना चाहिए:
Application.Worksheets("Database").Cells(k, ColumnOfInterest).Select
With Selection
.FormatConditions.Delete
.FormulaR1C1 = "=RC[-3] =""A"""
.FormatConditions.Add Type:=xlExpression, Formula1:=.FormulaR1C1Local
.FormatConditions(1).Interior.ColorIndex = 6
.Formula = ""
.FormulaR1C1 = "=RC[0] ="""""
.FormatConditions.Add Type:=xlExpression, Formula1:=.FormulaR1C1Local
.FormatConditions(2).Interior.ColorIndex = 5
.Formula = ""
End With