VBA: check if string in cell has a value. If yes, add 1 to a specific cell, if not, leave it.

TerenceTitus

New Member
Joined
Feb 8, 2017
Messages
20
Hi,

sorry I am stuck, your help is very much appreciated. I am struggling to think of how I can use VBA to check for a number in a cell (string - e.g. 8, 11, 18). Then I would like to tabulate the total numbers into a table of how many cells contained that number.

Here is how the data looks like. Act is for the type of activity. The numbers in the data represent the type of material used.
E.g. for person 1 (row 1), for Act 2 he used let's say (number 3) sand. Person 4 (row 4) also used (number 3). It should add up the total number of times each material is used for each activity.

Act1
Act2
Act3
Act4
Act5
Act6
Act7
396,1111
33,5114,83
5,1185116
93,109811

<tbody>
</tbody>

Here is an example of how the tabulated table would look like based on the data above. Mat is for materials.

Mat1
Mat<strike></strike>2
Mat<strike></strike>3
Mat<strike></strike>4
Mat<strike></strike>5
Mat6<strike></strike>
Mat7<strike></strike>
Mat<strike></strike>8
Mat<strike></strike>9
Mat10
Mat<strike></strike>11
Act111
Act<strike></strike>22111
Act<strike></strike>3111
Act<strike></strike>41<strike></strike>1<strike></strike>
Act<strike></strike>51111
Act<strike></strike>6121
Act<strike></strike>7112

<tbody>
</tbody>

The VBA does not need to generate a pivot table, just create this table in a different sheet is good enough.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Does it really need to be vba?
I think this formula copied across and down does what you want.

Excel Workbook
ABCDEFGHIJKL
1Act1Act2Act3Act4Act5Act6Act7
2396,1111
333,5114,83
45,1185116
593,109811
6
7
8Mat1Mat2Mat3Mat4Mat5Mat6Mat7Mat8Mat9Mat10Mat11
9Act100100000100
10Act200201000011
11Act300101000100
12Act400000001001
13Act500001100101
14Act600010002001
15Act700100100002
Count Materials (2)
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,185
Members
449,071
Latest member
cdnMech

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