Solved

Perform multiplications on grey shaded cells using VBA

Posted on 2013-12-11
7
296 Views
Last Modified: 2013-12-11
Dear Experts:

I would like to perform the following action using VBA on the current workbook

... Look for grey shaded cells (RGB 222, 222, 222) in all worksheets of the current workbook with exception of one named 'MasterSheet'
... If found perform the following multiplication:
C5 (Cell reference in worksheet 'MasterSheet') times the value found in that grey shaded cell
... Do the loop with this multiplication.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
  • 3
  • 2
  • 2
7 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39710970
Andreas,

Do you mean replace the value in the shaded cell with itself multiplied by C5 on the master sheet, or something else? "Do the loop with this multiplication." isn't really clear to me.

Regards,
Rory
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39710978
Sub mulgrey()
    Dim cel As Range
    For Each cel In ActiveSheet.UsedRange.Cells
        If cel.Interior.Color = RGB(222, 222, 222) Then
            cel.Value = Sheets("Mastersheet").Range("C5") * cel.Value
        End If
    Next cel
End Sub
0
 

Author Comment

by:AndreasHermle
ID: 39710998
Hi Roy,

ok, the requirements were not clear, I have to admit.

It is: the value in the grey shaded cell times C5 (MasterSheet)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:AndreasHermle
ID: 39711000
Hi ssaqibh:

we are almost there, thank you very much. The multiplication is only performed on the active sheet, but there are grey shaded cells in all worksheets. The multiplication is not to be performed in the 'MasterSheet' worksheet.

Thank you, Regards, Andreas
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 39711020
I'll leave it to Saqibh then as he's pretty much done it already. :)
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39711032
Sorry, I missed the "All worksheets" part.

Sub mulgrey()
    Dim cel As Range
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Mastersheet" Then
            For Each cel In ws.UsedRange.Cells
                If cel.Interior.Color = RGB(222, 222, 222) Then
                    cel.Value = Sheets("Mastersheet").Range("C5") * cel.Value
                End If
            Next cel
        End If
    Next ws
End Sub
0
 

Author Closing Comment

by:AndreasHermle
ID: 39711107
ssaqibh:

great this did the trick. Thank you very much for your professional help.

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to open excel in 2016 is slow 4 21
increment numbers by 10 11 30
Manually enter date in datepicker 24 35
remove upper case characters in excel 4 15
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now