下面是报告的半成品代码,在这里我无法按颜色(红色)对范围进行排序。如果可以帮助我编写一行代码,那将真的很有帮助。
If Len(Range("F" & i).Value) > 40 Then Range("F" & i).Interior.Color = RGB(255, 0, 0)
Sheets("FundHoldings").Sort.SortFields.Add(Range("F" & i), 1, 1, , 0).SortOnValue.Color = RGB(255, 0, 0)
下面是我到目前为止编写的代码:
Sub RV_Kuhns()
Dim StrFile As String
Dim Wb As Workbook
Dim Ws As Worksheet
Dim StrPath As String
Dim RowStart As Long
Dim LastRow As Long
Dim i As Long
StrPath = "C:\Users\Desktop\Index\"
StrFile = Dir(StrPath)
'Do While Len(StrFile) > 0
Set Wb = Workbooks.Open(StrPath & StrFile)
Sheets("FundHoldings").Select
'// First row starts from the word security name
RowStart = Cells.Find("Security Name", , , xlWhole).Row
'// Last row used would be total - 1
LastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
For i = RowStart To LastRow
'// If shares market value, accurals, security price < 0 then add del in column Z
If Evaluate("SUMPRODUCT(--(G" & i & ":J" & i & "<=0))") Then Range("Z" & i).Value = "Del"
'// IF sedol is - then
If Range("C" & i).Value = "-" Then Range("Z" & i).Value = "Del"
'// Make sure sedol is 7 characters 0000000
Range("C" & i).NumberFormat = "0000000"
'// Trim Security name for extra spaces
Range("F" & i).Value = Trim(Range("F" & i).Value)
'// Check length Greater than 40 and sort
If Len(Range("F" & i).Value) > 40 Then Range("F" & i).Interior.Color = RGB(255, 0, 0)
'Sheets("FundHoldings").Sort.SortFields.Add(Range("F" & i), 1, 1, , 0).SortOnValue.Color = RGB(255, 0, 0)
'// Del security Name begining with &
If Left("F" & i, 1) = "&" Then Range("Z" & i).Value = "Del"
'If Range("Z" & i).Value = "Del" Then Range("Z" & i).EntireRow.Delete
Next i
'StrFile = Dir
'Loop
End Sub