Hello everyone,
I have a data in excel and I want to create a macro which will count for me the number of cells in the column which contains a specified value and I want to paste the count of that cells next to that data in excel. Right now I'm using this code:
The thing is I don't know how to change the msgbox to the pasting the count into that sheet with data (next to table for example). To be honest I'm open to other solutions - the main objective is to count each of the cell in the specified column and paste that data into the worksheet instead of appearing msgbox. And I need to make it 'universal' (the number of rows of the column B may change with different file). Something like the table below.
[TABLE="width: 500"]
<tbody>[TR]
[TD]First Column: Name[/TD]
[TD]Second Column: Sex[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Abc[/TD]
[TD]Men[/TD]
[TD]Number of 'men'[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Aac[/TD]
[TD]Women[/TD]
[TD]Number of 'women'[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Bac[/TD]
[TD]Men[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bcc[/TD]
[TD]Women[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thank you.
I have a data in excel and I want to create a macro which will count for me the number of cells in the column which contains a specified value and I want to paste the count of that cells next to that data in excel. Right now I'm using this code:
Code:
[COLOR=blue]Dim[/COLOR] lCount [COLOR=blue]As[/COLOR] [COLOR=blue]Long[/COLOR]
lCount = WorksheetFunction.CountIf(Range("B1").EntireColumn, "Men")
MsgBox lCount
lCount = WorksheetFunction.CountIf(Range("B1").EntireColumn, "Women")
MsgBox lCount
The thing is I don't know how to change the msgbox to the pasting the count into that sheet with data (next to table for example). To be honest I'm open to other solutions - the main objective is to count each of the cell in the specified column and paste that data into the worksheet instead of appearing msgbox. And I need to make it 'universal' (the number of rows of the column B may change with different file). Something like the table below.
[TABLE="width: 500"]
<tbody>[TR]
[TD]First Column: Name[/TD]
[TD]Second Column: Sex[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Abc[/TD]
[TD]Men[/TD]
[TD]Number of 'men'[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Aac[/TD]
[TD]Women[/TD]
[TD]Number of 'women'[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]Bac[/TD]
[TD]Men[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Bcc[/TD]
[TD]Women[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
Thank you.