Macro: If X then return Y on next sheet.

Lorr81

New Member
Joined
Mar 21, 2016
Messages
38
Hi,

I have a two sheets and I need to copy data from sheet one and paste it in sheet 2, the issue is that each contact on sheet 1 has a field called country of birth which is fine however to use that information and paste it next to their record on sheet 2 but with a reference number instead of the word, not even sure if this is possible but would be grateful for any help.

Please see below:

Sheet 1 - Country - Column ISheet 2 - Ref - Column K
Libya434
New Caledonia540
St Vincent and the Grenadines670
Tanzania Untd Republic of834
Liechtenstein438
New Zealand554
Saint Pierre and Miquelon666
Thailand764
Lithuania440
Nicaragua558
Samoa882
Timor-Leste626
Luxembourg442
Niger562
San Marino674
Togo768
Macao446
Nigeria566
Sao Tome and Principe678
Tokelau772
Macedonia the former Yugoslav Republic of807
Niue570
Saudi Arabia682
Tonga776
Madagascar450
Norfolk Island574
Senegal686
Trinidad and Tobago780
Malawi454
Northern Mariana Islands580
Serbia688
Tunisia788
Malaysia458
Norway578
Seychelles690
Turkey792
Maldives462
Oman512
Sierra Leone694
Turkmenistan795
Mali466
Pakistan586
Singapore702
Turks and Caicos Islands796
Malta470
Palau585
Sint Martin (Dutch part)534
Tuvalu798
Marshall Islands584
Palestine, State of275
Slovakia703
Uganda800
Martinique474
Panama591
Slovenia705
Ukraine804
Mauritania478
Papua New Guinea598
Solomon Islands90
United Arab Emirates784
Mauritius480
Paraguay600
Somalia706
United Kingdom826
Mayotte175
Peru604
South Africa710
United States840
Mexico484
Philippines608
South Georgia and the South Sandwich Islands239
US Minor Outlying Islands581
Micronesia Federated States of583
Pitcairn612
South Sudan728
Unknown999
Moldova498
Poland616
Spain724
Uruguay858
Monaco492
Portugal620
Sri Lanka144
Uzbekistan860
Mongolia496
Puerto Rico630
St Helena Ascension & Tristan da Cunha654
Vanuatu548
Montenegro499
Qatar634
Sudan736
Venezuela862
Montserrat500
Reunion638
Suriname740
Viet Nam704
Morocco504
Romania642
Svalbard and Jan Mayen744
Virgin Islands British92
Myanmar104
Russian Federation643
Swaziland748
Virgin Islands U.S.850
Mozambique508
Rwanda646
Sweden752
Wallis and Futuna876
Namibia516
Saint Barthelemy652
Switzerland756
Western Sahara732
Nauru520
Saint Kitts and Nevis659
Syrian Arab Republic760
Yemen887
Nepal524
Saint Lucia662
Taiwan Province of China158
Zambia894
Netherlands528
Saint Martin (French part)663
Tajikistan762
Zimbabwe716

<colgroup><col><col></colgroup><tbody>
</tbody>

Thank you.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,
the reference number does not exist on sheet 1 only the country, If I could even find and replace I could then copy to sheet 2.
 
Upvote 0
So on sheet1 column I you have country names

And on sheet2 column K you have reference numbers

So how would a script know which reference number matches up with Sweden for example?
 
Upvote 0
Ok, so in sheet 1 I have column I which contains the countries,
In sheet 2 I have Column K which is Blank,
I need to search sheet 1 column I and if Libya is found the macro will populate Sheet 2 Column K with the Ref 434. If drafted the following macro to find and replace on sheet 1 which seems to work I just need to figure out how to set it to only change Sheet 1.

Sub Multi_FindReplace()




Dim sht As Worksheet
Dim fndList As Variant
Dim rplcList As Variant
Dim x As Long


fndList = Array("Libya", "New Caledonia", "St Vincent and the Grenadines", "Tanzania Untd Republic of", "Liechtenstein", "New Zealand", "Saint Pierre and Miquelon", "Thailand", "Lithuania")
rplcList = Array("434", "540", "670", "834", "438", "554", "666", "764", "440")


'Loop through each item in Array lists
For x = LBound(fndList) To UBound(fndList)
'Loop through each worksheet in ActiveWorkbook
For Each sht In "SF Export"
sht.Cells.Replace What:=fndList(x), Replacement:=rplcList(x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next sht

Next x


End Sub


Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,216,998
Messages
6,133,943
Members
449,849
Latest member
nnnyyy

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