/ / podświetlanie zgodnie z kolumną i zapisz jako xlsx używając VB - excel-vba, vba, excel

podświetlanie zgodnie z kolumną i zapisz jako xlsx używając VB - excel-vba, vba, excel

Próbuję dodać podkreślenie oparte na wartości w kolumnie i zapisz plik jako .xlsx ... Nie wydaje się jednak uzyskać poprawną składnię. Dziękuję Ci :)

" 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:TorrentSetupClinical"
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

Odpowiedzi:

0 dla odpowiedzi № 1

Czy to jest ten fragment, który daje błędy?

  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

Powinno być:

  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