I want to create a macro that will turn a block (rows and columns) of data into a table. Ought to be easy, except that the number of rows of data will vary from month to month, and I want the macro to deal with that on its own, so I don't have to define the table's size manually.
This code will correctly define the columns and rows to be included in the table:
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
But then using the macro recorder to create the table results in the following lines of code:
ActiveSheet.ListObjects.Add(xlSrcRange, [highlight #FCE94F]Range("$A$1:$K$84")[/highlight], , xlYes).Name = _
"Table4"
Range("Table4[#All]").Select
Problem: next month, the table won't run from A1 to K84. It may run from A1 to K50 or A1 to K107 (those are arbitrary row numbers).
What do I need to have in place of the highlighted text above? Or, for that matter, that whole line of code?
This code will correctly define the columns and rows to be included in the table:
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
But then using the macro recorder to create the table results in the following lines of code:
ActiveSheet.ListObjects.Add(xlSrcRange, [highlight #FCE94F]Range("$A$1:$K$84")[/highlight], , xlYes).Name = _
"Table4"
Range("Table4[#All]").Select
Problem: next month, the table won't run from A1 to K84. It may run from A1 to K50 or A1 to K107 (those are arbitrary row numbers).
What do I need to have in place of the highlighted text above? Or, for that matter, that whole line of code?