Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
This code is to find the array Transit in column E then replace it but for some reason, the rng variable and FirstAddress remain blank?
I could send the workbook if that helps?
I could send the workbook if that helps?
VBA Code:
Option Explicit
Sub Vehicle_Name_Replace()
Dim FirstAddress As String
Dim MyArr As Variant
Dim ws As Worksheet
Dim rng As Range, DRng As Range
Dim x As Long
Dim i As Long
Dim VModel As ComboBox
Set VModel = Body_And_Vehicle_Type_Form.Model_Type
Set ws = ThisWorkbook.Worksheets("Job Card Master")
MyArr = Array("Transit")
With ws.Range("E:E")
For i = LBound(MyArr) To UBound(MyArr)
Set rng = .Find(What:=MyArr(i), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
Set DRng = rng
Select Case VModel.Value
Case ("Sprinter")
DRng.Value = "Sprinter"
Case ("Master")
DRng.Value = "Master Movano NV400"
Case ("Movano")
DRng.Value = "Master Movano NV400"
Case ("NV400")
DRng.Value = "Master Movano NV400"
Case ("Boxer")
DRng.Value = "Boxer Ducato Relay"
Case ("Ducato")
DRng.Value = "Boxer Ducato Relay"
Case ("Relay")
DRng.Value = "Boxer Ducato Relay"
End Select
Set rng = .FindNext(rng)
Loop While Not rng Is Nothing And rng.Address <> FirstAddress
End If
Next i
End With
End Sub