Varinace given the destination name

mariamhalday

New Member
Joined
Nov 29, 2013
Messages
3
Hi ,

One more help needed with the experts here . I have sheet with data in column A ,column B Its a numeric data. I want compare two columns with each other and copy the unigue values to column C. As the number can be repeated multiple times in each columns. Against each unique value I want the variance of that value in Columns D. Further in Column E against the unique value If variance is found then Mark in which column the variance is found (Eg: ColumnA or ColumnB .
I searched a lot n many forum and finally got code .I have the code which works fine .It gives results up to variance found but I wanted a little extra .I wanted to know in which column the variance is present . If some one could help me with this I would really thankful.

Thanks n advance.

CODE:



<tbody>
</tbody>





<style> .ExternalClass .ecxhmmessage P { padding:0px; } .ExternalClass body.ecxhmmessage { font-size:12pt; font-family:Calibri; } </style> Sub countVar()
Dim sh As Worksheet, lr As Long, rng As Range
Set sh = Sheets(1)
lr = sh.Cells.Find("*", , xlFormulas, xlPart, xlByRows, xlPrevious).Row
Set rng = sh.Range("A2:A" & lr)
For Each c In rng
If Application.CountIf(sh.Range("C2:C" & lr), c.Value) = 0 Then
sh.Cells(Rows.Count, 3).End(xlUp)(2) = c.Value
x = Application.CountIf(rng, c.Value)
y = Application.CountIf(sh.Range("B2:B" & lr), c.Value)
If x = y Then
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = x
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 2) = 0
Else

If x > y Then
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = x
Else
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = y
End If
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 2) = Abs(x - y)
End If
End If
Next
For Each c In Range("B2:B" & lr)
If Application.CountIf(sh.Range("C2:C" & lr), c.Value) = 0 Then
sh.Cells(Rows.Count, 3).End(xlUp)(2) = c.Value
x = Application.CountIf(rng, c.Value)
y = Application.CountIf(sh.Range("B2:B" & lr), c.Value)
If x = y Then
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = x
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 2) = 0
Else

If x > y Then
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = x
Else
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 1) = y
End If
sh.Cells(Rows.Count, 3).End(xlUp).Offset(0, 2) = Abs(x - y)
End If
End If
Next
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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