I'm trying to create a table based upon user inputs: number of Areas, number of Floors, and number of Buildings.
Example output:
I figured out how to use VBA to copy/paste X Amount of columns (buildings) based on user input.
I figured out how to filldown in VBA for the areas.
I can't add floors automatically.
I can't tie it all together in the table.
Example code for the columns being added:
Private Sub cmd_Button_Columns_Click()' Add BuildingsDim N As IntegerN = Range("A2").ValueSelect Case NCase 1' Copy_Sheet = "Employing VBA Macros"Copy_Cell = "f1:i7"' Paste_Sheet = "Employing VBA Macros"Paste_Cell = "k1:n7"' Worksheets(Copy_Sheet).Range(Copy_Cell).CopyMe.Range(Copy_Cell).Copy' Worksheets(Paste_Sheet).Range(Paste_Cell).PasteSpecialMe.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllCase 2Copy_Cell = "f1:i7"Paste_Cell = "k1:n7"Me.Range(Copy_Cell).CopyMe.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllPaste_Cell = "p1:s7"Me.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllCase 3Copy_Cell = "f1:i7"Paste_Cell = "k1:n7"Me.Range(Copy_Cell).CopyMe.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllPaste_Cell = "p1:s7"Me.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllPaste_Cell = "u1:x7"Me.Range(Paste_Cell).PasteSpecial Paste:=xlPasteAllCase 0Range("k1:z7").ClearContentsEnd SelectEnd Sub
Example code for the rows:
Sub Add_Areas()' Add AreasDim Resizer As IntegerDim a As Varianta = InputBox("Please enter the MAX number of Areas for your project", "NUMBER OF AREAS") 'First we ask for user inputOn Error GoTo notvalid 'We add an error handler, so if the user would enter text like "seven", the sub will exit with a messageResizer = CInt(a) 'we store the input in a variable which has to be an integer, if the user enters text it will couse an error so we jump to the endIf Resizer < 2 Then GoTo notvalid 'We also check if the number is higher than 1, othervise it couses error, or copies the 19th row to the 20thOn Error GoTo 0 'We reset the error handling so we can see if something else goes wrong.ThisWorkbook.Sheets("Sheet1").Visible = TrueThisWorkbook.Sheets("Sheet1").SelectThisWorkbook.Sheets("Sheet1").Rows(20 + 1).EntireRow.Insert shift:=xlDown 'add a new row under the 20th row/above the 21st rowThisWorkbook.Sheets("Sheet1").Rows(20).Resize(Resizer).FillDownExit Sub 'We exit the sub before the error message.notvalid: 'in case of error we jump here MsgBox "Please enter a number which is 2 or higher"End Sub