2010-06-04 204 views
0

我有一張如下所示的表格。我怎樣才能讓Excel在第4列中放置具有相同編號的組的邊框,以便圍繞組存在邊框。我正在考慮條件格式可以做到這一點,但我想不出如何。所以我認爲唯一的選擇是宏觀。任何人都可以幫忙嗎?在具有相同值的單元格周圍創建邊框

1 64436 549419 1 
2 64437 549420 1 
3 64438 549421 1 
4 64439 549422 1 
5 64440 549423 1 
6 64441 549424 1 
7 64442 549425 1 
8 64443 549426 1 
9 64444 549427 1 
10 64445 549428 1 
11 64446 549429 1 
12 64447 549430 1 
13 64448 549431 2 
14 64449 549432 2 
15 64450 549433 2 
16 64451 549434 2 
17 64452 549435 2 
18 64453 549436 2 
19 64454 549437 2 
20 64455 549438 2 
21 64456 549439 2 
22 64457 549440 4 
23 64458 549441 4 
24 64459 549442 5 
25 64460 549443 5 
26 64461 549444 5 
27 64462 549445 5 
28 64463 549446 5 
29 64464 549447 5 
30 64465 549448 6 
31 64466 549449 6 
32 64467 549450 6 
33 64468 549451 6 
34 64469 549452 6 
35 64470 549453 6 
36 64471 549454 6 
37 64472 549455 9 
38 64473 549456 9 
39 64474 549457 9 
+0

參見https://superuser.com/問題/ 524678/excel-how-to-conditional-format-a-thick-bottom-border-to-an-whole-row-based-on和https://www.extendoffice.com/documents/excel/4046- Excel的附加邊界時,價值changes.html – 2017-06-01 13:08:56

回答

2

您需要使用相對引用。

  1. 選擇您想要進行條件格式化的列範圍。
  2. 在自己的情況輸入以下三個公式:
    • = AND($ C2 = $ C3,C3 $ = $ C4)
      • 這一個是對中間項。 (在兩側上邊框)
    • = AND($ C2 <> $ C3,C3 $ = $ C4)
      • 這一個是該組中的第一個。 (上左,上邊界,右)
    • = AND($ C2 = $ C3,C3 $ <> $ C4)
      • 這一個是最後在組中。 (左,下邊框,右)
  3. 格式如您所願。

將'$ C'全部替換爲'$ {Your Column}'。請注意,這不會在單個項目周圍放置任何邊框,因爲您可以在選區中不再有三個條件格式條件。

0

我推出了這個解決方案,它在我的Excel 2010上很奇怪:/ 我無法在2003年測試它,所以請讓我知道如果這很好。

Sub PaintBorder() 
Dim iRow As Integer 
iRow = 1 
Dim strTemp As String 
strTemp = Range("D" & iRow).Value 
Dim strPrev As String 

Dim sectionStart As Integer 
sectionStart = 1 

Do 
    strPrev = strTemp 
    strTemp = Range("D" & iRow).Value 

    If strPrev <> strTemp Then 
     ActiveSheet.Range(Cells(sectionStart, 1), Cells(iRow - 1, 4)).BorderAround xlSolid, xlMedium, xlColorIndexAutomatic 
     sectionStart = iRow 
    End If 
    iRow = iRow + 1 
Loop Until strTemp = vbNullString 
End Sub 
0

你只是想讓人眼更易讀嗎?如果是這樣,我建議交替的背景顏色。例如,每當第四列中的數字發生變化時,背景顏色將從白色變爲藍色,反之亦然。我此做所有的時間:

  1. 使一個附加列E.由於參考列是d,輸入:
    = MOD(IF(D5 <> D4,E4 + 1,E4),2 )
    (即,如果該行的列d是從最後一行的d不同,則改變從0至1或1至0)

  2. 隱藏列,以便最終用戶不會看到它。

  3. 製作2個條件公式。如果您的隱藏值爲0,則第一個會將行顏色更改爲白色。如果您的隱藏值爲1,則第二個會將其更改爲藍色。

沒有宏。沒有VBA編碼。只有1個隱藏的列和一些條件公式。而且顏色還是應交替正常,即使你的列d被跳過數:)

(我用這個每天在2003 XL我希望它可以在2007年)

1

我不能看到一個簡單的非宏解決方案正是你需要的,但PowerUser的解決方案似乎沒問題。

這是一個基於宏的解決方案,它將在最後一列中具有相同數字的行放置一個邊框。我會假設你的數據在A:D列中。

要使用此宏,只需單擊列表中的任意單元格,然後觸發宏。

用作快速指南:

  • AddBorders是簡單地通過在最後一列的所有單元格循環和作品出主宏時邊框是適當
  • AddBorder是一個簡短的程序,增加了邊境。
  • 作爲獎勵,AddBorder選擇從Excel的56調色板隨機顏色,使每個邊界都不同的顏色,使便於觀看

    Sub AddBorders() 
        Dim startRow As Integer 
        Dim iRow As Integer 
        startRow = 1  
        For iRow = 2 To ActiveCell.CurrentRegion.Rows.Count  
         If WorksheetFunction.IsNumber(Cells(iRow + 1, 4)) Then 
          If Cells(iRow, 4) <> Cells(iRow - 1, 4) Then 
           AddBorder startRow, iRow - 1 
           startRow = iRow 
          End If 
         Else 
           AddBorder startRow, iRow 
         End If 
        Next iRow  
    End Sub 
    
    Sub AddBorder(startRow As Integer, endRow As Integer) 
        Dim borderRange As Range 
        Dim randomColor As Integer 
        randomColor = Int((56 * Rnd) + 1) 
        Set borderRange = Range("A" & startRow & ":D" & endRow) 
        borderRange.BorderAround ColorIndex:=randomColor, Weight:=xlThick  
    End Sub 
    
相關問題