Shaikh Aziz
New Member
- Joined
- Dec 18, 2020
- Messages
- 35
- Office Version
- 2007
- Platform
- Windows
Please find below samples, where I want to do coding for rest of my actual data set,
ColumnA has multiple states name, ColumnB has unique values, and in columnC we want a sumif of columnB & Merging cells results based on states name (columnA).
Our result would be come in columnC after sum of ColumnB with mergecells based on columnA.
I have tried below codings,
Dim ColumnA as long
Dim ColumnC as long
ColumnsC = 0
ColumnA = Worksheets("Sheet1").Cells(2, 1).value
Lastrow = Worksheets("sheet1").cells(Rows.Count, 1).End(xlUp).Row
For i = 2 to lastrow
IF Worksheets("Sheet1").Cells(i, 1).value = ColumnA Then
ColumnC = ColumnC + Worksheets("Sheet1").cells(i, 3).value
End if
Next
worksheets("sheet1").cells(2, 3).value = ColumnC
But it's calcuating for columnA (first state only).
Please help me to finding perfect coding.
Thankyou !!!
ColumnA has multiple states name, ColumnB has unique values, and in columnC we want a sumif of columnB & Merging cells results based on states name (columnA).
ColumnA | ColumnB | ColumnC |
Maharashtra | 5 | 25 |
Maharashtra | 10 | |
Maharashtra | 10 | |
Gujarat | 30 | 180 |
Gujarat | 40 | |
Gujarat | 50 | |
Gujarat | 60 | |
Odisha | 80 | 313 |
Odisha | 50 | |
Odisha | 70 | |
Odisha | 68 | |
Odisha | 45 |
I have tried below codings,
Dim ColumnA as long
Dim ColumnC as long
ColumnsC = 0
ColumnA = Worksheets("Sheet1").Cells(2, 1).value
Lastrow = Worksheets("sheet1").cells(Rows.Count, 1).End(xlUp).Row
For i = 2 to lastrow
IF Worksheets("Sheet1").Cells(i, 1).value = ColumnA Then
ColumnC = ColumnC + Worksheets("Sheet1").cells(i, 3).value
End if
Next
worksheets("sheet1").cells(2, 3).value = ColumnC
But it's calcuating for columnA (first state only).
Please help me to finding perfect coding.
Thankyou !!!