OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 421
- Office Version
- 2019
- Platform
- Windows
Thanks in advance for your assistance. Why do I get the error "Run-time error '1004': Application-defined or object-defined error" for the following line of code
in the following code.
Excel Formula:
.Range("B" & i) = "=PROPER(" & CompanyName & ")"
in the following code.
Excel Formula:
Sub PrprCompNm()
Dim i As Long
Dim CompanyName As String
Dim LastRowIndex As Long
With Sheets("Index")
LastRowIndex = .Cells.Find(What:="*", After:=.Cells(1), _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
'Loop - remove "<empty>" and correct names to make sure not in all caps
For i = 2 To LastRowIndex
With Sheets("Index")
CompanyName = .Range("B" & i)
If CompanyName = "<empty>" Then
.Range("B" & i) = ""
CompanyName = .Range("B" & i)
End If
.Range("B" & i) = "=PROPER(" & CompanyName & ")"
End With
Next i
End Sub