I need your help please. I am new to using ranges as variables, so there maybe something obvious I'm missing but I can't seem to find a solution after a lot of googling.
I am formatting four sheets of data (headings, pretty fill colour, nice borders). They are all pretty much the same, but they have a varying number of columns. To save repetitious code I've written one procedure to do the formatting and another to change the variables and call the formatting code.
sample of the calling code:
' Set Customer detail variables.
varGlobalID = Sheets(varWST1Dockets).Cells(2, 13).Value
varCustomerName = Sheets(varWST1Dockets).Cells(2, 14).Value
' Format Suspended
' Set Variables
varReportHeading = "Suspended Dockets Investigation"
Set rngDataHeadings = Range("B11", "T11")
Range("B1048576").End(xlUp).Select
Set rngDataTable = Range(Selection, "T11")
Range("B1048576").End(xlUp).Select
Set rngData = Range(Selection, "T12")
' Run Format Reports Procedure
Sheets(varWSSuspended).Select
Call FormatReports
sample of formatting code
' Format Data Headings
rngDataHeadings.Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = -4300032
.PatternTintAndShade = 0
End With
With Selection.Font
.ColorIndex = 2
.TintAndShade = 0
.Bold = True
End With
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
' Apply Borders
rngDataTable.Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 2
.TintAndShade = 0
.Weight = xlMedium
End With
The code seems to work on the first run of the variables but not the second. Do I need to unload them before resetting? Or am I doing something else stupidly obviously wrong?
Thanks in advance.