Create Two Dimension Array with Numbers
Option Base 1
Public SH As Worksheet
Function InputWorksheet()
Set SH = ThisWorkbook.Sheets("InputData")
End Function
Function LastRow()
LastRow = SH.Range("A" & Rows.Count).End(xlUp).Row
End Function
Sub Create_Two_Dimension_Array_Optionbase_1()
'www.Tricks12345.com
InputWorksheet
SH.Range("B2:G33").Clear
Dim IntData(30, 5) As Integer
'================================
RowNumber = 1
For RowIndex = 1 To 30
'MsgBox RowIndex
For ColIndex = 1 To 5
IntData(RowIndex, ColIndex) = SH.Range("A" & RowNumber).Value
RowNumber = RowNumber + 1
Next
Next
MsgBox UBound(IntData)
MsgBox LBound(IntData)
'=====================================
For RowIndex = LBound(IntData) To UBound(IntData)
For ColIndex = 1 To 5
If RowIndex = 1 Then
SH.Cells(RowIndex + 1, ColIndex + 2).Activate
SH.Cells(RowIndex + 1, ColIndex + 2).Value = ColIndex
FormattingHeaderData
End If
If ColIndex = 1 Then
SH.Cells(RowIndex + 2, ColIndex + 1).Activate
SH.Cells(RowIndex + 2, ColIndex + 1).Value = RowIndex
FormattingHeaderData
End If
SH.Cells(RowIndex + 2, ColIndex + 2).Activate
'SH.Cells(RowIndex + 2, ColIndex + 2).Value = IntData(RowIndex, ColIndex)
SH.Cells(RowIndex + 2, ColIndex + 2).Value = "(" & RowIndex & ", " & ColIndex & ") = " & IntData(RowIndex, ColIndex)
FormattingData
Next
Next
End Sub
Function FormattingData()
With ActiveCell
.Font.Size = 15
.Font.Name = "Century"
.Font.ColorIndex = 9
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Columns.AutoFit
End With
End Function
Function FormattingHeaderData()
With ActiveCell
.Font.Size = 15
.Font.Name = "Century"
.Font.ColorIndex = 11
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Function