我嘗試做與條件相對應的顏色線,這里是我的資料庫:

我想在 libelle=XV28 時為線條著色
我做到了 :
Option Compare Text
Sub Bouton3_Cliquer()
Dim Derniere_ligne As Long
Dim ligne_en_cours As Long
Dim libelle As String
Derniere_ligne = Cells(Rows.Count, 2).End(xlUp).Row
For ligne_en_cours = 2 To Derniere_ligne
libelle = Cells(ligne_en_cours, 5).Value
If libelle = "XV28" Then
libelle = Cells(ligne_en_cours, 5).Value
Cells(ligne_en_cours).Interior.ColorIndex = 4
End If
Next
End Sub
但它不起作用,我只有第一行顏色,但它是名稱的列
謝謝你讀我
PS:我想知道如何在不說自己的情況下擁有列數。
例如,在這段代碼中:
Sub reset()
Dim Derniere_ligne As Long
Dim ligne_en_cours As Long
Dim libelle As String
Derniere_ligne = Cells(Rows.Count, 2).End(xlUp).Row
For ligne_en_cours = 2 To Derniere_ligne
libelle = Cells(ligne_en_cours, 4).Value
If libelle = "XZ" Then
Rows(ligne_en_cours).Interior.ColorIndex = 1 'this will change colour for whole row
End If
Next
End Sub
我說
libelle = Cells(ligne_en_cours, 4).Value
但是我想替換每個 libelle 索引的 4,因為有時我會回傳 4,因為我可以多擁有 1 列,然后一切都是錯誤的。
提前致謝
uj5u.com熱心網友回復:
也許像這樣
If libelle = "XZ" Then
rows(ligne_en_cours).Interior.ColorIndex = 4 'this will change colour for whole row
End If
如果你想要一個單元格,你需要提供行號和列號
cells(RowNumber, ColumnNumber)
或者你可以使用這樣的范圍Range("A" & ligne_en_cours & ":D" & ligne_en_cours).Interior.ColorIndex = 4
uj5u.com熱心網友回復:
我能看到的幾件事是一個問題:
If libelle = "XV28" Then需要閱讀XZCells(rowNum,colNum)有一個行和列組件(你的If陳述句中只有一行)......也許你想要Rows()而不是Cells()- 驗證您是否在
Columns(5)/Range("E:E")
如果這些標準都得到滿足,你應該搖擺不定。
uj5u.com熱心網友回復:
我想知道如何在不說自己的情況下擁有列數。
例如,在這段代碼中:
Sub reset()
Dim Derniere_ligne As Long
Dim ligne_en_cours As Long
Dim libelle As String
Derniere_ligne = Cells(Rows.Count, 2).End(xlUp).Row
For ligne_en_cours = 2 To Derniere_ligne
libelle = Cells(ligne_en_cours, 4).Value
If libelle = "XZ" Then
Rows(ligne_en_cours).Interior.ColorIndex = 1 'this will change colour for whole row
End If
Next
End Sub
我說
libelle = Cells(ligne_en_cours, 4).Value
但是我想替換每個 libelle 索引的 4,因為有時我會回傳 4,因為我可以多擁有 1 列,然后一切都是錯誤的。
提前致謝
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/479535.html
下一篇:洗掉重復標題時
