根据列突出显示并使用VB保存为xlsx

时间:2015-02-23 16:54:46

标签: excel-vba vba excel

我正在尝试根据列中的值添加一些突出显示并将文件另存为.xlsx ...但我似乎无法获得正确的语法。谢谢:))

' Highlight classifications
 For iRow = 2 To rData.Rows.Count 'Start at line #2 to ignore the header row
 Set rw = rData.Rows(iRow)

  If rw.Cells(iRow, iClassification).Value = "VUS" Then
 rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 6    'Yellow
ElseIf rw.Cells(iRow, iClassification).Value = "not provided" Then _
 rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 21    'Purple
ElseIf rw.Cells(iRow, iClassification).Value = "likely pathogenic" Then _
 rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 9    ' Dark Red
End If
Next iRow
End If

' Create new workbooks based on name
 Dim sSave As String
 Dim sFN As String
 Dim Directory As String
 Beep
 sSave = MsgBox("The data has been formatted and classified. Do you want to save the workbook now?", vbQuestion + vbYesNo)
If sSave = vbYes Then
Matrix 'Call the matrix routine
    sFN = [A1] & "_hg19annovar.xlsx"
    Directory = "N:\Torrent\Setup\Clinical\"
    ActiveWorkbook.SaveAs Filename:=Directory & sFN, FileFormat:=51
    Application.DisplayAlerts = True
    Application.Quit
    If sFN = "False" Then Exit Sub
Else
    MsgBox "This workbook has not yet been saved!", vbExclamation
End If
End Sub

1 个答案:

答案 0 :(得分:0)

这是错误的吗?

  If rw.Cells(iRow, iClassification).Value = "VUS" Then
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 6    'Yellow
  If rw.Cells(iRow, iClassification).Value = "not provided" Then _
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 21    'Purple
  If rw.Cells(iRow, iClassification).Value = "likely pathogenic" Then _
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 9    ' Dark Red
End If

应该是:

  If rw.Cells(iRow, iClassification).Value = "VUS" Then
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 6    'Yellow
  ElseIf rw.Cells(iRow, iClassification).Value = "not provided" Then _
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 21    'Purple
  ElseIf rw.Cells(iRow, iClassification).Value = "likely pathogenic" Then _
     rw.Cells(iRow, iClassification).EntireRow.Interior.ColorIndex = 9    ' Dark Red
End If