Counting Cells VBA

bagos

New Member
Joined
Jul 10, 2014
Messages
1
I've been searching all forums related to my question for quite some time and I cant seent to find the answer. I have an undetermined amount of worksheets. All worksheets are formated exactly the same. Each worksheet has a list of questions (33 of them) with Yes, No and N/A answers as a drop down option. Each sheet also has one drop down option with the colors Red, White, Black, Green and Purple. I need a macro that will count and add the "Yes" from Cell A3 from all sheets that have the criteria of the spefic color and then place that number in another sheet titled X. With this final number I'm planing on doing a percentage on all sheets. So if I have 2 worksheets that have the value "Yes" in A3 and are "Red" and two others that have the value "No" in A3 and are "Red" as well I want 50% on the last X sheet, cell "whatever". And if I have two worksheets with "Yes" on A16 and are "Green" and 8 worksheets with "No" on A16 and are "Green" then I will get a value of 20%.
I have very limited knowledge on VBA and the following is a humble try at this massive issue. For now I'm just trying to the count on a msgbox but it keeps poping a msgbox for each sheet with the number one. Any help would be great.


Sub Percentage()

Dim truevalue, colorvalue As String
Dim ws As Worksheet
Dim ct As Double

For Each ws In worksheets

ws.Select
colorvalue = Range("A3").Value
truevalue = Range("D6").Value

If colorvalue = "Red" And truevalue = "Yes" Then
ct = ws.Range("D6").Count
MsgBox ct

End If

If colorvalue = "Green" Then

MsgBox "Green is Good" 'Here goes what needs to be done when is green

End If

Next

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi bagos - Welcome to the forum! I think you are very close with your code. You might consider the code below. It will take the name of each worksheet and place it in column A of worksheet "x" starting at A1. You could then do the same for the values you want and place them in column B and the colors in column C. It would then be easy to go into worksheet "x" and calculate your data. Hope this helps get you started.

Code:
Sub bagos_List_Sheets()
'List names of all worksheets in workbook and place them in column A starting at A1
Sheets("x").Select
    For i = 1 To Sheets.count
        Cells(i, 1).Select
        Cells(i, 1) = Sheets(i).Name
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,659
Members
449,178
Latest member
Emilou

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