Kode saya ada di VBA dan memperbarui nilai sel berdasarkan dua kriteria. Saya telah mengomentari kode saya dengan cukup luas, jadi saya akan menempelkannya di bawah terlebih dahulu. Saya telah mengubah komentar dengan menambahkan dua apostrof lagi agar lebih mudah membedakan antara komentar dan kode di platform ini.
Sub HighlightValues()
'''Shortcut key: ctrl + w
'''Highlights values of corresponding left-most cell, if two conditions are met:
'''The part is in "L" class and all of the rightmost cells are empty
Dim ws As Worksheet
Dim i As Long, lastrow As Long, lastcolumn As Long, c As Long, d As Long, j As Long, count As Long, k As Long, report As Long
Set ws = Sheets("QAP")
lastrow = ws.Cells(Rows.count, 1).End(xlUp).Row
lastcolumn = ws.Cells(1, ws.Columns.count).End(xlToLeft).Column
'''Searches column titles for "Analysis Task Count"
'''where it will start searching for filled boxes on each row
For i = 1 To lastrow
If InStr(ws.Cells(1, i), "Analysis Task Count") Then
'''c is the number of column that Analysis Task Count is in
c = i - 1
End If
Next
'''Searches column titles for "Required by RPC"
'''where it will search for whether the part is "L' or not
For d = 1 To lastcolumn
If InStr(ws.Cells(1, d), "Required by RPC") Then
'''k is the number of column that Required by RPC is in
k = d
End If
Next d
'''For each row that part data is in
For i = 11 To lastrow
count = 0
'''If any cells past Analysis Task Count are filled, remember that
For j = c To lastcolumn
If Not IsEmpty(ws.Cells(i, j)) Then
count = 1
End If
Next j
'''If the stage is L and all the cells are empty for that row
If Cells(i, k).Value = ("L") And count = 0 Then
'''Highlight the first box in green
Cells(i, 1).Interior.Color = RGB(102, 255, 102)
Else
'''Or if thats not true, then make that box clear
Cells(i, 1).Interior.Color = xlNone
report = report + 1
End If
Next i
MsgBox (report)
End Sub
Untuk memandu Anda menelusuri kode, (kecuali spasi, beberapa pemformatan tidak terbawa), kode pertama-tama mencari nomor kolom dari dua kolom penting, lalu di perulangan for terakhir, untuk setiap baris, ia mencari apakah dua kriteria terpenuhi. Jika kriteria terpenuhi, sel berubah menjadi hijau, jika tidak, diisi kosong. Saya telah menghabiskan waktu sekitar satu jam untuk memastikan bahwa nilai yang dikembalikan oleh k dan c keduanya merupakan nomor kolom yang benar: Saya rasa bukan itu masalahnya. Selain itu, ketika saya mengatur penghitungan untuk melihat berapa kali kode melewati perulangan for terakhir, dan setiap pernyataan if, saya mendapatkan jumlah siklus yang benar.
Ini sangat membuat frustrasi, satu-satunya hal yang aneh adalah kode tersebut dieksekusi hampir seketika, jadi tidak ada penundaan sama sekali. Dan tentu saja, isi sel tidak berubah. Untuk mengujinya, saya menjalankan kode yang mengisi sel dengan warna oranye, dan tidak ada perubahan pada sel apa pun.
Terima kasih atas bantuan apa pun yang bisa saya dapatkan!