Count values in column (referring to column name in code)

maya_bee

New Member
Joined
Apr 5, 2022
Messages
3
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Current.png shows a simple example of my dataset. I want to count every value in column furniture and eventually get the dataset as shown in wanted-outcome.png. However, the code needs to look at the column name and not the column number. I want to use the vba for different sheets where column furniture may not always be in the same place.

I tried several things but neither came close. Any suggestions?
 

Attachments

  • current.PNG
    current.PNG
    4.4 KB · Views: 13
  • wanted-outcome.PNG
    wanted-outcome.PNG
    5.5 KB · Views: 13

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
It is hard to work with pictures. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
A simple example:
Map1
AB
1ownerfurniture
2mikechair
3janetable
4tomchair
5lillychair
6arilamp
7mayasofa
8anthonylamp
Blad1


I would like to add a new column groupsize that shows how often a furniture occurs. So chair occurs 3 times. In the column groupsize where furniture is 'chair' they value will be 3'.

Wanted outcome:
Map1
ABC
1ownerfurnituregroupsize
2mikechair3
3janetable1
4tomchair3
5lillychair3
6arilamp2
7mayasofa1
8anthonylamp2
Blad1


Thanks for the tip Mumps.
 
Upvote 0
Place this formula in cell B2 and copy it down as far as you have data:
=COUNTIF(B:B,B2)
 
Upvote 0
I know of the formula, however I'm trying to get it in vba. I'm trying to write a vba script with multiple mutations, so that the person using the script only has to perform one action.
 
Upvote 0
I'm trying to write a vba script with multiple mutations
Can you describe the multiple mutations? Also, can you use the XL2BB add-in to post screenshots instead of pictures of your data? It's hard to work with pictures.
 
Upvote 0

Forum statistics

Threads
1,223,937
Messages
6,175,513
Members
452,650
Latest member
Tinfish

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