Change the shape colour

rashmiranjan86

New Member
Joined
Mar 21, 2022
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
Hi All,
I am preparing a dashboard where I have 100 square shapes in sheet 1. In Sheet 2 Cell A1, I have the total number of books. I wanted to colour the shapes based on the cell value.
e.g. if I am putting 10 in Sheet2 Cell A1, then Sheet1 out of 100 square shapes, first 10 shapes should change the colour to orange and rest will remain as it it. Is it possible?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Yes, it is possible but for that ensure that the shapes have a particular naming format. For example "Rectangle 1","Rectangle 2","Rectangle 3" and so on...

Is this what you are trying?

VBA Code:
Option Explicit

Sub Sample()
    Dim wsA As Worksheet, wsB As Worksheet
   
    '~~> Change these to relevant sheets
    Set wsA = Sheet1: Set wsB = Sheet2
   
    Dim i As Long
    Dim MaxShpNo As Long
   
    '~~> Check if there is a value in A1 of Sheet2
    If Len(Trim(wsB.Range("A1").Value2)) <> 0 Then
        '~~> Check if the value is greater than 0
        If Val(wsB.Range("A1").Value2) > 0 Then
            '~~> Get the max value
            MaxShpNo = Val(wsB.Range("A1").Value2)
            '~~> Loop through the shapes and color the shapes to orange
            For i = 1 To MaxShpNo
                '~~> Change name of shape here
                wsA.Shapes("Rectangle " & i).Fill.ForeColor.RGB = RGB(255, 165, 0)
            Next i
        End If
    End If
End Sub

1647913587747.png
 
Upvote 0

Forum statistics

Threads
1,214,958
Messages
6,122,475
Members
449,087
Latest member
RExcelSearch

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