Advertisement
YasserKhalil2019

T4176_Replace All Old Name With New Names Using 1D Arrays

Oct 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. https://excel-egy.com/forum/t4167
  2. ---------------------------------
  3.  
  4. Sub Replace_All_Old_Name_With_New_Names_Using_1D_Arrays()
  5. Dim oldNames, newNames, ws As Worksheet, i As Long
  6.  
  7. With ThisWorkbook.Worksheets(1)
  8. oldNames = ConvertTo1DArray(.Range("C6:C" & .Cells(Rows.Count, "C").End(xlUp).Row).Value)
  9. newNames = ConvertTo1DArray(.Range("D6:D" & .Cells(Rows.Count, "D").End(xlUp).Row).Value)
  10. End With
  11.  
  12. Application.ScreenUpdating = False
  13. For i = LBound(oldNames) To UBound(oldNames)
  14. For Each ws In ThisWorkbook.Worksheets
  15. If ws.Index <> Worksheets(1).Index Then
  16. ws.Cells.Replace What:=oldNames(i), Replacement:=newNames(i), LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
  17. End If
  18. Next ws
  19. Next i
  20. Application.ScreenUpdating = True
  21.  
  22. MsgBox "Done...", 64
  23. End Sub
  24.  
  25. Function ConvertTo1DArray(arr As Variant)
  26. Dim b(), s As String, i As Long
  27. ReDim b(0 To UBound(arr, 1) - 1)
  28.  
  29. For i = 1 To UBound(arr, 1)
  30. b(i - 1) = arr(i, 1)
  31. Next i
  32.  
  33. ConvertTo1DArray = b
  34. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement