Create shapes based on filtered rows in a table

liberovago

New Member
Joined
Sep 6, 2020
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Good afternooneveryone!!!

I would need to automate the process of creating rectangles.

So:

I have a table (where there are rows that change from week to week, some are deleted, and some are added). Of the rows I add, I should create rectangles, and then export them to other sheets.

Before and after this process there are already a whole series of macros that help me; at the moment the operation I described, I do it manually. But I would like to automate it.

So I have this table, which I filter based on the newly created rows (which are products): I would like a macro to create rectangles for me, and as the text in the rectangle, comes a link to the cell where there is a description of that product. Example the form "Rectangle6" in the formula bar has =G!BA78 (G is the name of the sheet, ba78 where there is the text that is to be displayed).

The problem is that when I filter the table, I don't know how to proceed, in the sense that out of the whole table, I only have a few rows of new products. I don't know how to tell it "create a rectangle of the first filtered row displayed (example row #7), then create a rectangle of the second filtered row displayed (example row #14), and so on.

A first step with code I sketched it out, and the first rectangle I can create. But then I don't know how to continue, because if I change the references, to my current knowledge, he creates the rectangle after me at the next row of the table, but not the displayed row, but the row of the whole table...

The code is this

VBA Code:
Sub CreateForms()
      
    ' Define the range of the filtered table
    Dim tblRange As Range
    Set tblRange = Range("Tabella4")

    ' Get the filtered rows of the table
    Dim tblRows As Range
    Set tblRows = tblRange.SpecialCells(xlCellTypeVisible)

    ' Define the cell that contains the formula
    Dim formulacell As Range
    Set formulacell = tblRows(1, 52).Offset(0, 1)

    ' Define the position and size of the shape
    Dim shapeLeft As Double
    shapeLeft = tblRange.Left + tblRange.Width + 10 ' 10 is the gap between the table and the shape
    Dim shapeTop As Double
    shapeTop = tblRange.Top
    Dim shapeWidth As Double
    shapeWidth = 100
    Dim shapeHeight As Double
    shapeHeight = 50

    ' Add the shape to the worksheet
    Dim shape As shape
    Set shape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, shapeLeft, shapeTop, shapeWidth, shapeHeight)

    ' Set the formula of the shape to the formula in the cell
    shape.DrawingObject.Formula = "=G!" & formulacell.Address(True, True, xlA1, External:=False)
    
End Sub

Sorry for my English!
 

Attachments

  • Catturas.JPG
    Catturas.JPG
    121.6 KB · Views: 9

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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