Replacing Values With Another Sheet's Value

mmertt900

New Member
Joined
Dec 18, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi Everybody,

I have a question for you. I have a workbook with two sheets. First one is main sheet with all the data and second one is kind of a description sheet. In the first sheet there are data's specify places but these are codes. For example SHANGHAİ comes as CNSHA. İn second sheet I define these places like below. What I want to do is loop through places in first sheet and replace them with second sheet's value. I've tried below code but it is not effective. I need your help.

First Sheet 'lets say A1First Sheet 'lets say B2Second Sheet ' lets say A1Second Sheet 'lets say A2
'some dataCNSHACNSHASHANGHAİ
'some dataKRPUSJPTYOTOKYO
'some dataJPTYOKRPUSBUSAN

VBA Code:
Dim Rng as Range

For Each Rng in Range("B2:B"&cell(rows.count,2).end(xlup).row)
Rng.Value=Sheets(2).cells.find(rng.value).offset(0,1).value
Next Rng
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What columns in sheet2 has the abbreviation & Name?
Also hows many rows of data do you have on each sheet?
 
Upvote 0
What columns in sheet2 has the abbreviation & Name?
Also hows many rows of data do you have on each sheet?
İn Sheet2 Column A has the abbrevation and Column B has the description.
First sheet(main sheet) has to be dynamic because I consolidate data's every week. But second sheet (Abbrevation Sheet) has almost 60 rows.
 
Upvote 0
Ok, how about
VBA Code:
Sub mmertt()
   Dim Cl As Range
   Dim Dic As Object
   
   Set Dic = CreateObject("scripting.dictionary")
   With Sheets("Sheet2")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Dic(Cl.Value) = Cl.Offset(, 1).Value
      Next Cl
   End With
   With Sheets("Sheet1")
      For Each Cl In .Range("B2", .Range("B" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then Cl.Value = Dic(Cl.Value)
      Next Cl
   End With
End Sub
Change sheet names to suit
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub mmertt()
   Dim Cl As Range
   Dim Dic As Object
  
   Set Dic = CreateObject("scripting.dictionary")
   With Sheets("Sheet2")
      For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         Dic(Cl.Value) = Cl.Offset(, 1).Value
      Next Cl
   End With
   With Sheets("Sheet1")
      For Each Cl In .Range("B2", .Range("B" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then Cl.Value = Dic(Cl.Value)
      Next Cl
   End With
End Sub
Change sheet names to suit
Oh man that's what I'm looking for. Thank you so much for your help.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top