Yashraj Jadhao
New Member
- Joined
- Nov 14, 2021
- Messages
- 9
- Office Version
- 2021
- Platform
- MacOS
I have solved this question but my code is not working which I have written below, please help me with correct VBA code.
Question: Label the spreadsheet as shown below.
Then write a macro named “MultiplicationTable” that: (1) reads the number typed in by the user
into cell B2 and stores in a variable named “number1”, (2) reads the number typed in by the user
into cell B3 and stores in a variable named “number2”, (3) uses a FOR loop structure to print a
column of numbers starting at a value of 1 and going all the way to the value of variable number1
where the first entry is in cell A6 (and subsequent values are in A7, A8, etc.), (4) uses a FOR loop
structure to print a row of numbers starting at a value of 1 and going all the way to the value of
variable number2 where the first entry is in cell B5 (and subsequent entries are in C5, D5, etc.),
and (5) use a loop structure to then print in the multiplication table where the result in each cell
starting in cell B6 and going down both in the columns and across in the rows is the product of
the number labels in column A multipled by the label value in Row 5.
ANSWER: This is my code but for some reason it is not working, please help.
Sub Button1_Click()
'Comment-Declaration of variables
Dim number1 As Integer
Dim number2 As Integer
'Comment-Defining varaibles
number1 = Int(Range("B2").Value)
number2 = Int(Range("B3").Value)
Dim cellidex As String
For i = 1 To number1
'Comment- Setting row index
cellindex = "A" & (i + 5)
'Comment-Setting. values with correspondence to index
Range(cellindex).Value = i
Next i
'Comment- Column header
For i = 1 To number1
For j = 1 To number2
cellindex = Chr(Asc("A" + i)) & 5
'Comment- Setting values with correspondence to index
Range(cellindex).Value = i
Next i
For i = 1 To number1
For j = 1 To number2
'Comment- Total cellindex
cellindex = Chr(Asc("A") + j) & (5 + i)
'Comment- Setting up multiplication values
Range(cellindex).Value = i * j
Next j
Next i
End Sub
Question: Label the spreadsheet as shown below.
Then write a macro named “MultiplicationTable” that: (1) reads the number typed in by the user
into cell B2 and stores in a variable named “number1”, (2) reads the number typed in by the user
into cell B3 and stores in a variable named “number2”, (3) uses a FOR loop structure to print a
column of numbers starting at a value of 1 and going all the way to the value of variable number1
where the first entry is in cell A6 (and subsequent values are in A7, A8, etc.), (4) uses a FOR loop
structure to print a row of numbers starting at a value of 1 and going all the way to the value of
variable number2 where the first entry is in cell B5 (and subsequent entries are in C5, D5, etc.),
and (5) use a loop structure to then print in the multiplication table where the result in each cell
starting in cell B6 and going down both in the columns and across in the rows is the product of
the number labels in column A multipled by the label value in Row 5.
A | B | C | |
1 | Multiplication Table Generator | ||
2 | User Input Number #1 = | ||
3 | User Input Number #2 = | ||
4 | |||
5 | X | ||
6 |
ANSWER: This is my code but for some reason it is not working, please help.
Sub Button1_Click()
'Comment-Declaration of variables
Dim number1 As Integer
Dim number2 As Integer
'Comment-Defining varaibles
number1 = Int(Range("B2").Value)
number2 = Int(Range("B3").Value)
Dim cellidex As String
For i = 1 To number1
'Comment- Setting row index
cellindex = "A" & (i + 5)
'Comment-Setting. values with correspondence to index
Range(cellindex).Value = i
Next i
'Comment- Column header
For i = 1 To number1
For j = 1 To number2
cellindex = Chr(Asc("A" + i)) & 5
'Comment- Setting values with correspondence to index
Range(cellindex).Value = i
Next i
For i = 1 To number1
For j = 1 To number2
'Comment- Total cellindex
cellindex = Chr(Asc("A") + j) & (5 + i)
'Comment- Setting up multiplication values
Range(cellindex).Value = i * j
Next j
Next i
End Sub