tự tô màu nếu giá trị ô thỏa điều kiện (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Tôi tuân thủ nội quy khi đăng bài

thierry henry

Thành viên mới
Tham gia
11/6/18
Bài viết
49
Được thích
4
đây là code được em ghi bằng cách chạy macros :

Sub Macro2()

Range("O2").Select

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _

Formula1:="=$J$2*50/100"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.Color = 255

.TintAndShade = 0

End With

Nhưng làm thế nào để nó tự động chạy hàng loạt từ O2 đến O10000

em cảm ơn
 
đây là code được em ghi bằng cách chạy macros :

Sub Macro2()

Range("O2").Select

Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLessEqual, _

Formula1:="=$J$2*50/100"

Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority

With Selection.FormatConditions(1).Interior

.PatternColorIndex = xlAutomatic

.Color = 255

.TintAndShade = 0

End With

Nhưng làm thế nào để nó tự động chạy hàng loạt từ O2 đến O10000

em cảm ơn
Đính kèm file được không?
 
Bạn thử sửa
Range("O2").Select thành
Range("O2:O10000").Select
thì nó sẽ so sánh toàn bộ vùng đó với ô J2 của bạn
nhưng mà mình nghĩ chắc bạn không định làm vậy mà mà là so sánh đối xứng 2 cột J và O
thì dùng thử cái này
Sub Macro2()
Dim vung As Range
Set vung = Range("O2:O10000")

vung.FormatConditions.Delete
With vung.FormatConditions.Add(Type:=xlCellValue, Operator:=xlLessEqual, Formula1:="=$J2*50/100")
.SetFirstPriority
With .Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
End With
End Sub
 
Lần chỉnh sửa cuối:
Web KT

Bài viết mới nhất

Back
Top Bottom