I create a lot of tables in my macro. So I am trying to create a module , table_mod , that generates tables and places it three rows below the existing last row and I plan to call the table_mod whenever I need to create tables. But I am running into the fact that I need my variables to be dependent on the table name that the user gives. For example:
Sub Main()
' Below are all the data that my macro will generate in its number crunching
var_12_count = "Jordan"
var_13_count = "Kobe"
var_21_count ="Rings"
var_22_count = 6
var_23_count = 5
var_title_count = "This table lists the number of rings won by Jordan and Kobe"
var_12_transpose = "Rings"
var_21_transpose = "Jordan"
var_31_transpose = "Kobe"
var_22_transpose = 6
var_32_transpose = 5
var_title_transpose = "This is the transpose of the previous table"
' My intention is to call table commands like this to spit out the earlier generated data in nicely formatted tables.
table_mod(2,3,"count")
table_mod(3,2,"transpose")
End Sub
Sub table_mod(row As Long, column As Long, name As String)
Set wb As ActiveWorkbook
Set ws As wb.ActiveSheet
With ws
lr = .Range("A" & .Rows.Count).End(xlUp).Row
.Cells(lr+3,1).Value = var_title_&name
For i = 1 To row
For j = 1 To column
.Cells(lr+6+i,j).Value = var_&CStr(i)&CStr(j)&_&name
Next j
Next i
End With
End Sub
The output should look like
This table lists the number of rings won by Jordan and Kobe
Jordan Kobe
Rings 6 5
This is the transpose of the previous table
Rings
Jordan 6
Kobe 5
But I don't know how to combine the variable values with strings so VBA would know to read the values from the correct variables.
I am open to any suggestions of creating formatted/standardized tables in some alternate fashion. I intend for all my tables to have identical formatting in terms of lines, fonts, colors etc but I have not included all those aspects of the code. Right now I am getting red colored lines and unexpected end messages on the lines. Thanks
If I get this to work, I hope to do with with every repetitive procedure, indeed every procedure in my macro. Which I am guessing is how everybody does things anyway.