我没有线索。
我尝试在每个 If then 块之后放置一个 End If,但显然这不起作用。有任何想法吗??
Private Sub putCollectionInWorksheet(ByRef ws As Excel.Worksheet, ByRef cData As Collection)
Dim i As Long, j As Long
Dim emp As Employee
i = 36 ' current row
For Each emp In cData
If emp.City = "Dallas" And emp.Title = "Associate" Then
ws.Cells(i, 3).Value = emp.Name
ws.Cells(i, 3).Interior.ColorIndex = 31
ws.Cells(i, 3).Font.Color = vbWhite
i = i - 1
Next emp
Else
If emp.City = "Denver" And emp.Title = "Associate" Then
ws.Cells(i, 4).Value = emp.Name
ws.Cells(i, 4).Interior.ColorIndex = 53
ws.Cells(i, 4).Font.Color = vbWhite
i = i - 1
Next emp
Else
If emp.City = "Houston" And emp.Title = "Associate" Then
ws.Cells(i, 5).Value = emp.Name
ws.Cells(i, 5).Interior.ColorIndex = 52
ws.Cells(i, 5).Font.Color = vbWhite
i = i - 1
Next emp
Else
If emp.City = "Kansas City (Missouri)" And emp.Title = "Associate" Then
ws.Cells(i, 6).Value = emp.Name
ws.Cells(i, 6).Interior.ColorIndex = 56
ws.Cells(i, 6).Font.Color = vbWhite
i = i - 1
Next emp
Else
If emp.City = "Oklahoma City" And emp.Title = "Associate" Then
ws.Cells(i, 7).Value = emp.Name
ws.Cells(i, 7).Interior.ColorIndex = 47
ws.Cells(i, 7).Font.Color = vbWhite
i = i - 1
Next emp
Else
If emp.City = "Tulsa" And emp.Title = "Associate" Then
ws.Cells(i, 8).Value = emp.Name
ws.Cells(i, 8).Interior.ColorIndex = 48
ws.Cells(i, 8).Font.Color = vbWhite
i = i - 1
Next emp
End If
End Sub
编辑
现在行是这样的
鲍勃 | 苏 | 艾伦 | 乔治
如果该系列遇到在达拉斯的合伙人亨利,它将被覆盖。
亨利 | 苏 | 艾伦 | 乔治
我需要它看起来像这样:
亨利 |
鲍勃 | 苏 | 艾伦 | 乔治
抱歉,由于防火墙,我无法显示屏幕截图。