TropicalMagic
New Member
- Joined
- Jun 19, 2021
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
Hi all,
I would like to find and replace all values, from “Viet Nam” to “Vietnam” in range A.
However, I found that finding and replacing values cell by cell is extremely slow, especially if the there are 1000+ rows in the range A
I would like to use Excel VBA and arrays as arrays speeds up the automation process greatly. I am also open to using scripting dictionaries.
Here is my worksheet layout:
Here is my code so far (does not work):
```
Dim ws As Worksheet
Dim x, LastRow As Long
Dim arrA As Variant
Set ws = Workbooks("MyWorkbook.xlsx").Sheets("MyWorksheet")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
arrA = ws.Range("A2:A" & LastRow).Value 'put the range in an array to make the iteration faster
For x = 1 To UBound(arrA)
If arrA = “Viet Nam” Then
arrA(x, 1) = “Vietnam”
End If
Next x
```
How do I fix the issue?
Many thanks!
I would like to find and replace all values, from “Viet Nam” to “Vietnam” in range A.
However, I found that finding and replacing values cell by cell is extremely slow, especially if the there are 1000+ rows in the range A
I would like to use Excel VBA and arrays as arrays speeds up the automation process greatly. I am also open to using scripting dictionaries.
Here is my worksheet layout:
Here is my code so far (does not work):
```
Dim ws As Worksheet
Dim x, LastRow As Long
Dim arrA As Variant
Set ws = Workbooks("MyWorkbook.xlsx").Sheets("MyWorksheet")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
arrA = ws.Range("A2:A" & LastRow).Value 'put the range in an array to make the iteration faster
For x = 1 To UBound(arrA)
If arrA = “Viet Nam” Then
arrA(x, 1) = “Vietnam”
End If
Next x
```
How do I fix the issue?
Many thanks!