Private Sub UserForm_Initialize()
Dim rngSource As Range
Set rngSource = Sheet1.Range("A1", Sheet1.Range("F20000").End(xlUp))
LoadData Me.iGrid1, rngSource
End Sub
Private Sub LoadData(ByVal iGrid As Control, ByVal SourceData As Range)
Dim lGridRow As Long, lGridCol As Long
Dim arrColWidth, arrColHRD, arrSource, aRes()
On Error Resume Next
arrSource = Intersect(SourceData, SourceData.Offset(1)).Value
arrColWidth = Array(90, 150, 290, 410, 410, 410)
arrColHRD = SourceData.Resize(1).Value
ReDim aRes(1 To UBound(arrSource, 1), 1 To UBound(arrSource, 2))
With iGrid
.BeginUpdate
.Font = "Times New Roman"
.Header.Font = "Times New Roman"
.Header.Font.Bold = True
.Header.Height = 25
.MultiSelect = True
.RowMode = True
.RowCount = UBound(arrSource, 1)
For lGridCol = 1 To UBound(arrColHRD, 2)
.AddCol lGridCol, arrColHRD(1, lGridCol), arrColWidth(lGridCol - 1), 1, 1, , 1
.ColHeaderForeColor(lGridCol) = &H800000
For lGridRow = 1 To .RowCount
aRes(lGridRow, lGridCol) = arrSource(lGridRow, lGridCol)
Next
Next
.LoadFromArray 1, 1, aRes, False
.EndUpdate
End With
If Err.Number Then MsgBox Err.Description
End Sub