{"id":13447,"date":"2021-12-12T08:01:19","date_gmt":"2021-12-12T08:01:19","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=13447"},"modified":"2021-12-12T08:01:46","modified_gmt":"2021-12-12T08:01:46","slug":"solved-vba-to-generate-multiple-shapes-based-on-number-in-cell","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/vba-to-generate-multiple-shapes-based-on-number-in-cell\/21268.html","title":{"rendered":"Solved VBA To Generate Multiple Shapes Based On Number In Cell"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I made a macro to create rectangles based on cell values for a 2D excel simulation. The code below adds the shapes once per each line I have in Sheet1:<\/p>\n<p>&nbsp;<\/p>\n<pre>Dim r As Long, s As Shape\r\n\r\n    For r = 3 To Sheets(\"Sheet1\").Cells(Rows.Count, 19).End(xlUp).Row\r\n        If Sheets(\"Sheet1\").Cells(r, 9).Value &gt; 0 Then\r\n            Set s = Sheets(\"AUTO\").Shapes.AddShape(msoShapeRectangle, 410, 10, _\r\n            Sheets(\"Sheet1\").Cells(r, \"S\"), _\r\n            Sheets(\"Sheet1\").Cells(r, \"T\"))\r\n                s.TextFrame2.TextRange.Text = _\r\n                  Sheets(\"Sheet1\").Cells(r, \"E\") &amp; \"; D=\" _\r\n                &amp; Sheets(\"Sheet1\").Cells(r, \"F\") &amp; \"; L=\" _\r\n                &amp; Sheets(\"Sheet1\").Cells(r, \"G\") &amp; \"; \" _\r\n                &amp; Sheets(\"Sheet1\").Cells(r, \"I\") &amp; \" batches; additional pcs: \" _\r\n                &amp; Sheets(\"Sheet1\").Cells(r, \"J\")\r\n        Else<\/pre>\n<p>Column 9 (I) sets the number of shapes to be created. Its values may vary from 0 to 10.<\/p>\n<p><b>So my need would be to integrate into the code above a condition so I could add the same shape multiple times based on the value on each row in column 9.<\/b><br \/>\n&#8211; if value in I3 is 1, it should add 1 shape of the type in row 3<br \/>\n&#8211; if value in I4 is 2, it should add 2 shapes of the type in row 4 and only then move on to the next row<br \/>\n&#8211; and so on<\/p>\n<p>Thank you in advance.<\/p>\n<p align=\"right\"><span style=\"font-size: xx-small;\"><i>message edited by Mrrrr<\/i><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":19},"question-category":[53],"question_tags":[],"class_list":["post-13447","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/13447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=13447"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=13447"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=13447"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=13447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}