Private Sub cmd_in6_Click()
Dim Arr, rng As Range, r As Long, c As Long
r = Worksheets("Bao cao").Range("A65536").End(xlUp).Row
With Worksheets("Bao cao").Range("A5:G" & r)
.ClearContents
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
End If
Worksheets("Bao cao").Range("D2").Value = cb_thang6.Value
Arr = ListBox7.List
ReDim Preserve Arr(LBound(Arr) To UBound(Arr), LBound(Arr, 2) To ListBox7.ColumnCount - 1)
For r = LBound(Arr) To UBound(Arr)
For c = LBound(Arr, 2) + 3 To UBound(Arr, 2)
Arr(r, c) = CDbl(Arr(r, c))
Next
Next
With Worksheets("Bao cao").Range("A5").Resize(UBound(Arr) - LBound(Arr) + 1, UBound(Arr, 2) - LBound(Arr, 2) + 1)
.Value = Arr
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
'Worksheets("Bao cao").Range("A2").Resize(UBound(Arr) - LBound(Arr) + 4, UBound(Arr, 2) - LBound(Arr, 2) + 1).Columns.AutoFit
' in bao cao
With Worksheets("Bao cao").PageSetup
'.Orientation = xlLandscape ' giay ngang
'.Orientation = xlPortrait'giay doc
.PrintTitleRows = "$1:$4"
.PrintTitleColumns = "$A:$G"
End With
Select_abc
Worksheets("Bao cao").Range("A1:G" & ListBox7.ListCount + 4).PrintOut
End Sub
Private Sub Select_abc()
Dim a As String
a = MsgBox("Chon trang ngang hay doc", vbYesNoCancel, "Thong bao")
If a = vbYes Then
ActiveSheet.PageSetup.Orientation = xlPortrait ' doc
'ActiveWindow.SelectedSheets.PrintOut
ActiveWindow.SelectedSheets.PrintPreview
ElseIf a = vbNo Then
ActiveSheet.PageSetup.Orientation = xlLandscape ' ngang
'ActiveWindow.SelectedSheets.PrintOut
ActiveWindow.SelectedSheets.PrintPreview
Exit Sub
End If
End Sub