
This is VBA Marcos program to calculate the tables using MS Excel sheet which get user input rows and columns to print multiplication tables in sheet.
This program is use to create tables i.e multiplication tables for number of rows and columns the user specify. User inputs the rows and columns in the table then using VBA Macros script program (Alt + F11), you can calculate multiplication.
Table and its output data is shown in below image:
Conditions for program to validate:
- Should accept only numerical
- Should clear old content after execution
- Should give error message popup box
- Number of rows should multiply by number of columns specified by users
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
Public Sub Table() Dim r, c Dim StrRow, StrCol Dim rownumber, colnumber As Integer Range("f6", "zz100").Cells.ClearContents '********* Storing Values in Variable********* StrRow = Cells(3, 3).Value StrCol = Cells(4, 3).Value '********* Validation *********** ' Row or column value left blank If StrRow = "" Then MsgBox "Row value can't be Blank", vbCritical Exit Sub ElseIf StrCol = "" Then MsgBox "Column value can't be Blank", vbCritical Exit Sub ' Other characters than Numeric ElseIf Not IsNumeric(Cells(3, 3).Value) Then MsgBox "Enter only numbers in Row", vbInformation Exit Sub ElseIf Not IsNumeric(Cells(4, 3).Value) Then MsgBox "Enter only numbers in column", vbInformation Exit Sub ElseIf (StrRow <= ) Then MsgBox "Entered value for Row is less than ZERO or Negative", vbInformation Exit Sub ElseIf (StrCol <= ) Then MsgBox "Entered value for Column is less than ZERO or Negative", vbInformation Exit Sub ' Less than 0.5 ElseIf StrRow < 0.5 Or StrCol < 0.5 Then MsgBox "Row Or Column value should be at least One." End If If StrRow = 0.5 Then Row = 1 End If If StrCol = 0.5 Then Col = 1 End If '******* For Printing Tables******** rownumber = 6 For r = 1 To Round(StrRow) Step 1 colnumber = 6 For c = 1 To Round(StrCol) Step 1 Cells(rownumber, colnumber).Value = c & "*" & r & "=" & r * c colnumber = colnumber + 1 Next rownumber = rownumber + 1 Next ' ****** End for Printing Tables ****** End Sub |
Download:
If you have any problem regarding this program or modification adding or deleting function, kindly respond with your valuable comments below.