I am trying to underline the rows from row 2 to the end, and double underline the first row. The number of rows can be different each time and the worksheets are between my variables StartIndex and EndIndex. Thanks!
Private Sub CommandButton4_Click()
Dim StartIndex As Long, EndIndex As Long, i As Long
Dim ws As Worksheet
Dim lookupValue As Range
Dim tableArray As Range
StartIndex = Sheets("Invoice").Index + 1
EndIndex = Sheets.Count
Dim intSheet As Integer
Dim arSheets() As String
Dim intArrayIndex As Integer
Dim lastRow As Long
Dim seriesOfRows As Range
Set tableArray = Sheets("Client List").Range("A1:C93")
intArrayIndex = 0
For intSheet = StartIndex To EndIndex
Set lookupValue = Sheets(intSheet).Range("A2")
If Sheets(intSheet).Name <> "Sheet1" Then
Sheets(intSheet).Rows(1).Insert
Sheets(intSheet).Rows(1).Range("D1") = Application.WorksheetFunction.VLookup(lookupValue, tableArray, 2, False)
LastMonth = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mm-yyyy")
Sheets(intSheet).Columns("A").Delete
With Sheets(intSheet).PageSetup.LeftHeaderPicture
.filename = "S:\Billing\Client billing\LogoDoNotTouch\cpc_302X181.jpg"
.Height = 70
.Width = 120
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.59
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
With Sheets(intSheet).PageSetup
.LeftHeader = "&G"
.CenterHeader = Sheets(intSheet).Range("C1")
.RightHeader = "Invoice Detail for " & LastMonth
.RightFooter = "Page &P of &N"
.LeftFooter = "Printed on &D"
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(1.5)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
End With
With Sheets(intSheet)
' lastRow = .UsedRange.Rows.Count
' lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set seriesOfRows = .Range(.Cells(2, 1), .Cells(lastRow, 1))
.Range("A2").Value = "Physician"
.Range("B2").Value = "Accession Number"
.Range("C2").Value = "Patient Name"
.Range("D2").Value = "Collection Date"
.Range("E2").Value = "Procedure (CPT)"
.Range("F2").Value = "Amount"
.Columns("D:F").HorizontalAlignment = xlCenter
.Columns("B").ColumnWidth = 15.67
.Columns("A").ColumnWidth = 20.22
With seriesOfRows
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
.Rows.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Rows(2).Font.Bold = True
.Rows(2).Borders.LineStyle = xlDouble
End With
Sheets(intSheet).Rows(1).Delete
ReDim Preserve arSheets(intArrayIndex)
arSheets(intArrayIndex) = Sheets(intSheet).Name
intArrayIndex = intArrayIndex + 1
End If
Next
' Sheets(arSheets).Select
End Sub
Private Sub CommandButton4_Click()
Dim StartIndex As Long, EndIndex As Long, i As Long
Dim ws As Worksheet
Dim lookupValue As Range
Dim tableArray As Range
StartIndex = Sheets("Invoice").Index + 1
EndIndex = Sheets.Count
Dim intSheet As Integer
Dim arSheets() As String
Dim intArrayIndex As Integer
Dim lastRow As Long
Dim seriesOfRows As Range
Set tableArray = Sheets("Client List").Range("A1:C93")
intArrayIndex = 0
For intSheet = StartIndex To EndIndex
Set lookupValue = Sheets(intSheet).Range("A2")
If Sheets(intSheet).Name <> "Sheet1" Then
Sheets(intSheet).Rows(1).Insert
Sheets(intSheet).Rows(1).Range("D1") = Application.WorksheetFunction.VLookup(lookupValue, tableArray, 2, False)
LastMonth = Format(DateSerial(Year(Date), Month(Date) - 1, 1), "mm-yyyy")
Sheets(intSheet).Columns("A").Delete
With Sheets(intSheet).PageSetup.LeftHeaderPicture
.filename = "S:\Billing\Client billing\LogoDoNotTouch\cpc_302X181.jpg"
.Height = 70
.Width = 120
.Brightness = 0.36
.ColorType = msoPictureAutomatic
.Contrast = 0.59
.CropBottom = 0
.CropLeft = 0
.CropRight = 0
.CropTop = 0
End With
With Sheets(intSheet).PageSetup
.LeftHeader = "&G"
.CenterHeader = Sheets(intSheet).Range("C1")
.RightHeader = "Invoice Detail for " & LastMonth
.RightFooter = "Page &P of &N"
.LeftFooter = "Printed on &D"
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(1.5)
.BottomMargin = Application.InchesToPoints(1)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
End With
With Sheets(intSheet)
' lastRow = .UsedRange.Rows.Count
' lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
Set seriesOfRows = .Range(.Cells(2, 1), .Cells(lastRow, 1))
.Range("A2").Value = "Physician"
.Range("B2").Value = "Accession Number"
.Range("C2").Value = "Patient Name"
.Range("D2").Value = "Collection Date"
.Range("E2").Value = "Procedure (CPT)"
.Range("F2").Value = "Amount"
.Columns("D:F").HorizontalAlignment = xlCenter
.Columns("B").ColumnWidth = 15.67
.Columns("A").ColumnWidth = 20.22
With seriesOfRows
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
.Rows.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Rows(2).Font.Bold = True
.Rows(2).Borders.LineStyle = xlDouble
End With
Sheets(intSheet).Rows(1).Delete
ReDim Preserve arSheets(intArrayIndex)
arSheets(intArrayIndex) = Sheets(intSheet).Name
intArrayIndex = intArrayIndex + 1
End If
Next
' Sheets(arSheets).Select
End Sub