如果该行中的两个单元格具有相同的值,我正在尝试为整行着色.这是我现在的代码:
For i = 2 To LastRow
If Worksheets("Request Results").Cells(i, 4).Value <> Worksheets("Request Results").Cells(i, 6).Value Then
Cells(i, 1).EnitreRow.Interior.ColorIndex = 255
ElseIf Worksheets("Request Results").Cells(i, 4).Value = Worksheets("Request Results").Cells(i, 6).Value Then
Cells(i, 1).EntireRow.Interior.ColorIndex = 5296274
End If
Next i
Run Code Online (Sandbox Code Playgroud)
循环首先进入else语句,我Cells(i, 1).EntireRow.Interior.ColorIndex = 5296274在行上得到"下标超出范围"错误,我不太清楚为什么.有谁知道可能导致此错误的原因是什么?我尝试过的一切都失败了.
我试图从一个工作表中搜索一列单元格,找到所有唯一值,然后将这些值粘贴到另一个工作表中的列中。到目前为止,我的代码可以创建字典,搜索所需的列,并选择该列中的所有唯一值。
Function UniqueRequest() As Long
myReqIDCol = ColSearch("id")
'Creates a dictionary filled with each unique value in the "TaskIDList" column and counts them to determine how many unique keys are in the document
Set dic = CreateObject("Scripting.Dictionary")
For i = 1 To LastRow
tmp = Cells(i, myReqIDCol).Value
If Not dic.exists(tmp) Then
dic.Add tmp, 1
End If
Next i
End Function
Run Code Online (Sandbox Code Playgroud)
我还有一个功能,可以选择要粘贴单元格的工作表并进行设置,以便将值粘贴到所需列中的每个连续空白单元格中。
Function ReqSheet(input_column As Integer, input_value As Long) As Long
Dim rv As Long
rv = 1
Sheets("Request Results").Activate
Do …Run Code Online (Sandbox Code Playgroud)