Find the column by name and to sum that column

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi everyone i am posting for 1st time in MrExcel, Help me to solve this.
Here is the table.
AppleBallCatDogElephant
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366
12343234324544366

<colgroup><col><col><col span="3"></colgroup><tbody>
</tbody>
From the above table i need to find "Ball" and sum that column and that should be shown in a particular cell in VBA
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try
Code:
Sub chk()
   Dim Fnd As Range

   Set Fnd = Range("1:1").Find("Ball", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Fnd.EntireColumn.Copy
End Sub

Dim Fnd As Range
Set Fnd = Range("1:1").Find("Sum of Other Earning Non Taxable", , , wlwhole, , , False, False)
If Not Fnd Is Nothing Then Fnd.EntireColumn.Copy

ecO6i.png


and sir i don't need to copy the entire column , only i need the values that are their in that particular column

Thank you in prior
 
Upvote 0
Thanks Fluff for your effort on trying this and making my work easier.
I need one more help that how i find the sum of particular column ..
1.I need to find the column by it's names
2.Then i need to do sum of that columns

(Like if i have Basic,HRA,PF,PT and some more other columns also, but i need to find the sum of only Basic,HRA and PF) and all that sum should be present in last column

BasicHRAPFPTESISum of Basic+HRA+PF
1234323432454436634879
1235003432454436634947
1232343432454436634681
12356433432454436640090
123543432454436634501
1233453432454436634792
1232133432454436634660
1234323432454436634879
1234323432454436634879
1233453432454436634792
1235463432454436634993
12354673432454436639914
123653432454436634512
123873432454436634534
12387683432454436643215
1237693432454436635216
1238793432454436635326
12398803432454436644327

<colgroup><col span="5"><col></colgroup><tbody>
</tbody>

Like this it should give me as output
Thanks in Prior
 
Last edited:
Upvote 0
How about
Code:
Sub GirishDhruva()
Range("F2", Range("E" & Rows.Count).End(xlUp).Offset(, 1)).Formula = "=SUMPRODUCT(($A$1:$E$1=""Basic"")+($A$1:$E$1=""HRA"")+($A$1:$E$1=""PF""),(A2:E2))"
End Sub
 
Upvote 0
Range("F2", Range("E" & Rows.Count).End(xlUp).Offset(, 1)).Formula

Instead of this can we perform that in ActiveCell, if we can means let me know how to perform that ASAP

Thank You
 
Upvote 0
How about
Code:
Sub GirishDhruva()
Range("F2", Range("E" & Rows.Count).End(xlUp).Offset(, 1)).Formula = "=SUMPRODUCT(($A$1:$E$1=""Basic"")+($A$1:$E$1=""HRA"")+($A$1:$E$1=""PF""),(A2:E2))"
End Sub
Hi Sir,
I didn't understood your concept, but i need to find the sum of particular cells like, if i need to find the sum of basic,hra,pf and that sum should be available in "LastCell" , as i wouldn't be knowing were my basic,hra,pf would be available , but it should search for that columns and then it should sum-up all those values in last column

Thanks in prior
 
Upvote 0
Which is the last column?
 
Upvote 0
Sir,Even Last column i should search (were lastcolumn+1 , the total should printed).

Right now my last column is 'X' but extra column might be added in next coming months , hence i should find out last column and sum should be available at last column
 
Last edited:
Upvote 0
How about
Code:
Sub GirishDhruva()
   Dim Nxt As Long
   Dim Hdr As String
   Nxt = Cells(1, Columns.Count).End(xlToLeft).Offset(, 1).Column
   Hdr = Range(Cells(1, 1), Cells(1, Nxt - 1)).Address(, , xlR1C1)
   Range(Cells(2, Nxt), Cells(Rows.Count, Nxt - 1).End(xlUp).Offset(, 1)).FormulaR1C1 = "=SUMPRODUCT((" & Hdr & "=""Basic"")+(" & Hdr & "=""HRA"")+(" & Hdr & "=""PF""),(rc1:rc[-1]))"
End Sub
 
Upvote 0
ya it worked exactly how i needed .
thanks a lot and can u please explain me how this runs, so that i can learn
thank you in proir
 
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,835
Members
449,343
Latest member
DEWS2031

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