generate ID variable using multiple conditions

Alvina

New Member
Joined
Jun 21, 2014
Messages
1
Hi!
I'm a beginner at VBA and I need some help.

I'm using three data sets with district data. Some district have the same name so I want to apply an ID number instead of using the district names. I have a numeric ID in one of the data sets. I now want to insert that ID in the two data sets without ID using the two conditions "if district name = district name AND province name = province name" then new variable = ID. How do I do that?!

Example:
First data set with ID (Districts with ID, some with the same name (two a:s) )

IDDistProv
1ae
2be
3ce
4ah

<tbody>
</tbody>

Second data set without ID and multiple observation per district

xDistProv
ae
ae
ce
ah

<tbody>
</tbody>

I did the following:

For i = 2 to 5
For j = 2 to 5
x = 0

if sheet1.cells(i,2) = sheet2.cells(j,2) AND sheet1.cells(i,3) = sheet2.cells(j,3) THEN

x = x + sheet1.cells(i,1)

End if

Next

sheet2.cells(j,1)=x

It is not working!

Please help me out!
Thank you
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Welcome to MrExcel.

Why do you need a macro for that? Formula in E2 copied down:


Excel 2010
ABCDEFG
1IDDistProvxDistProv
21ae1ae
32be1ae
43ce3ce
54ah4ah
Sheet1
Cell Formulas
RangeFormula
E2=INDEX(A$2:A$5,MATCH(1,INDEX((B$2:B$5=F2)*(C$2:C$5=G2),),FALSE))
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,679
Members
449,463
Latest member
Jojomen56

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