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) )
<tbody>
</tbody>
Second data set without ID and multiple observation per district
<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
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) )
ID | Dist | Prov |
1 | a | e |
2 | b | e |
3 | c | e |
4 | a | h |
<tbody>
</tbody>
Second data set without ID and multiple observation per district
x | Dist | Prov |
a | e | |
a | e | |
c | e | |
a | h |
<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