Solved

Perform multiplications on grey shaded cells using VBA

Posted on 2013-12-11
7
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

688 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