Excel VBA Object Populate Cell

Copper Contributor

Hi! I have a bunch of objects for a visual representation that I can select and mark certain colors using macros. I just wanted to see if I mark a certain object can I have it auto populate a cell with certain data.

 

Sub Fabric()
'
' Fabric Macro
'
' Keyboard Shortcut: Ctrl+w
'
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 32, 96)
        .Transparency = 0.5
        .Solid
    End With
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 32, 96)
        .Transparency = 0.5
        .Solid
    End With
End Sub

 

 

9 Replies

@itsmatta 

Which cell would you like to populate with what?

@Hans Vogelaar 

It would be AM3, which is a dropdown list, so if it was "Fabric" there's an option to select F.

itsmatta_0-1662467150494.png

 

@itsmatta 

You'll have to explain in MUCH more specific detail what you want to do.

If you reference the image I posted. Those little objects are referencing a visual representation of conduits underground 1-84. I click on conduit 1 and can mark it by pressing ctrl+w to highlight it the color using VBA. I just wanted to know if I click object "1" I can have it update AM3 based whatever key I press. Really hard to explain without almost doing a video demo.

@itsmatta 

How do I know which shape is related to which cell?

@Hans Vogelaar 

Only that shape can only update or populate one cell

 

Screenshot 2022-09-06 100755.png

@itsmatta 

Sub Fabric()
'
' Fabric Macro
'
' Keyboard Shortcut: Ctrl+w
'
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.RGB = RGB(0, 32, 96)
        .Transparency = 0.5
        .Solid
    End With
    Range("AM3").Value = "F"
End Sub
What if I click object "conduit #2", which should populate AM4?

@itsmatta 

Write a similar macro for that object, with AM4 instead of AM3.

 

If you want a more generic approach, I repeat my earlier question: how do we know which object corresponds to which cell, and which value should we use?