我想知道是否有人知道如何選擇一個矩形範圍的值?這個範圍不會被修復。對於這個特定的例子,它將以矩形形式選擇B5-G7,然後它將設置條件格式以添加某些顏色。運行時錯誤1004當試圖選擇一個矩形範圍的值
我已經嘗試它給我一個錯誤,在這個部分
ActiveSheet.Cells(colorrow & "2", _
ActiveSheet.Cells(colorrow & "2").End(xlDown).End(xlToRight)).Select
不知道是否有人知道爲什麼codebut?會很感激!
我試圖寫了一些編碼。
我的代碼如下:
Sub Macro2()
Dim thevaluestocopy As Variant, colorCell as Range, colorrow as Long, thefirstcolorrow as Long
colorrow = 1
Do
Set colorCell = Sheets("Sheet1").Cells(colorrow, 1)
'check for test1-test6 if its around do nothing, else goes to the next row and next column
If colorCell = "test1" Or colorCell = "test2" Or colorCell = "test3" _
Or colorCell = "test4" Or colorCell = "test5" Or colorCell = "test6" _ Then
'Do nothing
Else
thefirstcolorrow = Sheets("Sheet1").Cells(colorrow, 2)
'This statement gives me the error.. not sure why it cant work
ActiveSheet.Cells(colorrow & "2", _
ActiveSheet.Cells(colorrow & "2").End(xlDown).End(xlToRight)).Select
Exit Do
End If
colorrow = colorrow + 1
Loop
'add colors into cell
ActiveCell.Select
Selection.FormatConditions.AddColorScale ColorScaleType:=3
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
xlConditionValueLowestValue
With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
.Color = 8109667
End With
Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
xlConditionValuePercentile
Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
.Color = 8711167
End With
Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
xlConditionValueHighestValue
With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
.Color = 7039480
End With
End Sub
我認爲有一個更好的方法來做到這一點。你能確認數據總是按照這個順序嗎?即「test1」在「droptest」或「最硬」或「最軟」之後不會出現? – 2012-03-16 11:51:07
yup ..它不會發生在那3個測試之後......但我認爲我的應該沒問題..我已經嘗試了一些例子,它實際上工作正常...... – user1204868 2012-03-16 13:26:57
好吧,我們將離開它在那: ) – 2012-03-16 14:03:43