I got a doubt/problem with VBA while creating a macro. Basically I want to apply a Table "Style" to my current selection which is the following:
Range("A1:J1").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
The macro I recorded then applies a Table with the following code:
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$J$319"), , xlYes).Name = _
"Table4"
ActiveSheet.ListObjects("Table4").TableStyle = "TableStyleLight15"
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Now what I am concerned about is in the really first line, the Range("$A$1:$J$319") which is clearly the interval I selected with the first three lines of code. Is there a way to make this range something like this?
ActiveSheet.ListObjects.Add(xlSrcRange, Range("Selection"), , xlYes).Name = _
"Table4"
I want something like this because my interval could change in the future (by being 50 lines less or more) and I don't want the table to be applied to empty or more lines...
I hope I explained myself clearly! Thank you!