0
我有代碼來輸入信息,然後將該信息與表進行比較。我想突出顯示正在創建的新行和我們正在比較新行的行。這裏是我的代碼突出顯示兩行
Sub findData()
Dim workflow As String
Dim finalrow As Integer
Dim i As Integer
With Sheets("Sheet1")
workflow = .Range("C5").Value
servergri = .Range("C9").Value
gridf = .Range("C9").Value
StartTime = .Range("c11").Value
End With
With Sheets("Sheet3")
finalrow = .Range("C" & Rows.Count).End(xlUp).Row
For i = 5 To finalrow
If .Cells(i, 3) = workflow And (.Cells(i, 4) = servergri Or .Cells(i, 5) = gridf) Then
.Rows(i).Insert
'Add new information to the new row.
'The new row number is still = i
.Cells(i, 3) = workflow
.Cells(i, 4) = servergri
.Cells(i, 6) = StartTime
'If you only want to add one row then your should exit the loop
Exit For
End If
Next
End With
Call Worksheet_SelectionChange
End Sub
Sub Worksheet_SelectionChange()
Dim Target As Range
Application.ScreenUpdating = False
' Clear the color of all the cells
Cells.Interior.ColorIndex = 0
' Highlight the active cell
Target.Interior.ColorIndex = 8
Application.ScreenUpdating = True
End Sub
你從來沒有設置'Target'是任何其他比'SelectionChange'宣佈它作爲一個'Range'後事件... – Dave
那麼如何將它分配給新的和比較行? @Dave –
'Private Sub Worksheet_SelectionChange(ByVal Target As Range)' – Slai