2012-10-29 12 views
22

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

सभी मदद की बहुत सराहना की जाती है!

Set DT = Sheets("DATA") 
endRow = DT.Range("F" & Rows.Count).End(xlUp).Row 
result = 3 

For I = 2 To endRow 
    If DT.Cells(I, 6).Value = Range("B1").Value Then 
     Range("A" & result) = DT.Cells(I, 6).Value 
     Range("B" & result) = DT.Cells(I, 1).Value 
     Range("C" & result) = DT.Cells(I, 24).Value 
     Range("D" & result) = DT.Cells(I, 37).Value 
     Range("E" & result) = DT.Cells(I, 3).Value 
     Range("F" & result) = DT.Cells(I, 15).Value 
     Range("G" & result) = DT.Cells(I, 12).Value 
     Range("H" & result) = DT.Cells(I, 40).Value 
     Range("I" & result) = DT.Cells(I, 23).Value 
     result = result + 1 
    End If 
Next I 
+1

मैं अपने शीर्षक देखा संपादित जैसे कि यह लोगों को भ्रमित। – CustomX

उत्तर

77

आप केवल करने के लिए कोड की एक पंक्ति की जरूरत है

Call SetRangeBorder(Range("C11")) 
Call SetRangeBorder(Range("A" & result)) 
Call SetRangeBorder(DT.Cells(I, 6)) 
Call SetRangeBorder(Range("A3:I" & endRow)) 
1

सीमाओं को जोड़ने के लिए यह कोशिश करते हैं, उदाहरण के लिए:

Range("C11").Borders(xlEdgeRight).LineStyle = xlContinuous 
Range("A15:D15").Borders(xlEdgeBottom).LineStyle = xlContinuous 

आशा है कि वाक्य रचना है क्योंकि मैं सी # में ऐसा करने के बाद सही है।

+0

वास्तव में मदद नहीं करता है, यह एक सीमा पर काम करेगा, लेकिन प्रति सेल नहीं। – CustomX

+0

और, यह वास्तव में क्या है: रेंज ("सी 11")। सीमाएं (xlEdgeRight) .लाइन स्टाइल = xlContinuous या यह: रेंज ("ए 15: ए 15")। सीमाएं (xlEdgeBottom) .लाइन स्टाइल = xlContinuous – Sylca

+0

आईडीक यही है कि आप ' मैंने अपने शुरुआती कोड में कुछ भी नहीं बनाया है। – CustomX

8

निम्नलिखित पैरामीटर के रूप में किसी भी सीमा के साथ कहा जा सकता है: एक और तरीका

Sub testborder() 

    Dim rRng As Range 

    Set rRng = Sheet1.Range("B2:D5") 

    'Clear existing 
    rRng.Borders.LineStyle = xlNone 

    'Apply new borders 
    rRng.BorderAround xlContinuous 
    rRng.Borders(xlInsideHorizontal).LineStyle = xlContinuous 
    rRng.Borders(xlInsideVertical).LineStyle = xlContinuous 

End Sub 
5

यहाँ:

Option Explicit 

Sub SetRangeBorder(poRng As Range) 
    If Not poRng Is Nothing Then 
     poRng.Borders(xlDiagonalDown).LineStyle = xlNone 
     poRng.Borders(xlDiagonalUp).LineStyle = xlNone 
     poRng.Borders(xlEdgeLeft).LineStyle = xlContinuous 
     poRng.Borders(xlEdgeTop).LineStyle = xlContinuous 
     poRng.Borders(xlEdgeBottom).LineStyle = xlContinuous 
     poRng.Borders(xlEdgeRight).LineStyle = xlContinuous 
     poRng.Borders(xlInsideVertical).LineStyle = xlContinuous 
     poRng.Borders(xlInsideHorizontal).LineStyle = xlContinuous 
    End If 
End Sub 

उदाहरण सीमा में प्रत्येक सेल के चारों ओर सीमा निर्धारित करें:

Range("A1:F20").Borders.LineStyle = xlContinuous

प्रत्येक सेल के चारों ओर सीमा पर कई प्रभाव लागू करना भी आसान है।

उदाहरण के लिए:

Sub RedOutlineCells() 
    Dim rng As Range 

    Set rng = Range("A1:F20") 

    With rng.Borders 
     .LineStyle = xlContinuous 
     .Color = vbRed 
     .Weight = xlThin 
    End With 
End Sub 
2

जब मैं मूल रूप से इस समस्या के लिए देख रहा था, लेकिन यहाँ मेरा अंतिम परिणाम था यह पेज नहीं मिला। ईमानदारी से देखा और SuperUsers में पोस्ट किया, लेकिन यकीन नहीं है कि वहाँ या यहां से संबंधित है।

नमूना कॉल

Call BoxIt(Range("A1:z25")) 

उपनेमका

Sub BoxIt(aRng As Range) 
On Error Resume Next 

    With aRng 

     'Clear existing 
     .Borders.LineStyle = xlNone 

     'Apply new borders 
     .BorderAround xlContinuous, xlThick, 0 
     With .Borders(xlInsideVertical) 
      .LineStyle = xlContinuous 
      .ColorIndex = 0 
      .Weight = xlMedium 
     End With 
     With .Borders(xlInsideHorizontal) 
      .LineStyle = xlContinuous 
      .ColorIndex = 0 
      .Weight = xlMedium 
     End With 
    End With 

End Sub 
0
xlWorkSheet.Cells(1, 1).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlDataBarBorderType.xlDataBarBorderSolid 
xlWorkSheet.Cells(1, 1).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlDataBarBorderType.xlDataBarBorderSolid 
xlWorkSheet.Cells(1, 1).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlDataBarBorderType.xlDataBarBorderSolid 
xlWorkSheet.Cells(1, 1).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlDataBarBorderType.xlDataBarBorderSolid 
संबंधित मुद्दे