Yes. It would be OK to set that last row count in the loop to a higher number than you expect to need, because the code already includes several lines which make sure there are values in the 3 critical cells in each row (Name, Equation, & Units). Since Comment is not critical, I deal with that differently. If the Comment cell was empty, I simply set its value as an empty string. Because if that cell was empty were empty, it might not have given our oComment variable a value, and that would cause it to throw an error when setting this variable as the value of the parameters comment. But when we set its value to an empty string, that avoids that potential error.
I'm not sure what other messages you are wanting, but I did add one more, where I thought it would be most useful in this situation. Since your initial post suggests your main goal is to update existing parameters, instead of creating new ones, I added a notification question in there for when a parameter by that name is not found, and asks you if you want to let the rule create that parameter for you. If you click No, it will skip to the next row in Excel. If you click Yes, it will create that parameter. I hope that is what you wanted.
Here is the updated code:
Dim oDocType As DocumentTypeEnum = ThisApplication.ActiveDocumentType
Dim oUParams As UserParameters
If oDocType = DocumentTypeEnum.kPartDocumentObject Or _
oDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
oUParams = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
ElseIf oDocType = DocumentTypeEnum.kDrawingDocumentObject Then
oUParams = ThisDrawing.Document.Parameters.UserParameters
End If
Dim oUParam As UserParameter
'specify Excel source file & sheet name
oFile = "C:\Temp\MyParams.xlsx"
oSheet = "Sheet1"
GoExcel.Open(oFile, oSheet)
GoExcel.DisplayAlerts = False
GoExcel.TitleRow = 2
GoExcel.FindRowStart = 3
Dim oRow, oCol As Integer
For oRow = 3 To 1000
Dim oName As String = GoExcel.CellValue("A" & oRow)
'if the Name cell of this row is empty, it will exit this main loop of rows
If String.IsNullOrEmpty(oName) Then Exit For
Dim oEquation As String = GoExcel.CellValue("B" & oRow)
'if the Equation cell of this row is empty, it will exit this main loop of rows
If String.IsNullOrEmpty(oEquation) Then Exit For
Dim oUnits As String = GoExcel.CellValue("C" & oRow)
'if the Units cell of this row is empty, it will exit this main loop of rows
If String.IsNullOrEmpty(oUnits) Then Exit For
Dim oComment As String = GoExcel.CellValue("D" & oRow)
If String.IsNullOrEmpty(oComment) Then oComment = ""
'if the Comment cell of this row is empty, it will NOT exit this main loop of rows
Dim oExists As Boolean = False
For Each oUParam In oUParams
If oUParam.Name = oName Then
oExists = True
oAnswer = MsgBox("A parameter named '" & oName & "' already exists." & vbCrLf & _
"Do you want to overwrite its value?", vbYesNo + vbQuestion + vbDefaultButton2, "PARAM EXISTS")
If oAnswer = vbNo Then
Exit For 'exits the parameters loop, not the Excel rows loop
ElseIf oAnswer = vbYes Then
oUParam.Expression = oEquation
oUParam.Comment = oComment
End If
End If
Next
If oExists = False Then
oAns = MsgBox("No parameter was found named " & oName & "." & vbCrLf & _
"Do you want it to be created?", vbYesNo + vbQuestion + vbDefaultButton2, "iLogic")
If oAns = vbNo Then
Exit For 'exits the parameters loop, not the Excel rows loop
ElseIf oAns = vbYes Then
oUParam = oUParams.AddByExpression(oName, oEquation, oUnits)
If Not String.IsNullOrEmpty(oComment) Then
oUParam.Comment = oComment
End If
End If
End If
Next
GoExcel.Close
Wesley Crihfield

(Not an Autodesk Employee)