Option Explicit
Private sheet As Worksheet
Private startCell As Range
Private dataRange As Range
Private Sub Class_Initialize()
End Sub
Public Sub Initialize(sheetName As String, startRow As Integer, startColumn As Integer)
Dim tmpSheet As Worksheet
Dim endCell As Range
For Each tmpSheet In Worksheets
If tmpSheet.name = sheetName Then
Set sheet = tmpSheet
End If
Next
If sheet Is Nothing Then
Worksheets.Add
ActiveSheet.name = sheetName
Set sheet = ActiveSheet
End If
Set startCell = sheet.Cells(startRow, startColumn)
Set endCell = sheet.Cells(startCell.End(xlDown).row, startCell.End(xlToRight).column)
Set dataRange = sheet.Range(startCell, endCell)
End Sub
Public Sub Clear()
sheet.Cells.ClearContents
End Sub
Public Function GetValue(rowKey As String, columnKey As String) As String
Dim cell As Range
Set cell = GetCell(rowKey, columnKey)
If cell Is Nothing Then
GetValue = ""
Else
GetValue = cell.value
End If
End Function
Private Function GetCell(rowKey As String, columnKey As String) As Range
Dim row As Integer
Dim column As Integer
Dim cell As Range
Dim keyBuf As String
Dim result As Range
If rowKey = "" Or columnKey = "" Then
Exit Function
End If
row = -1
For Each cell In dataRange.Columns(1).Cells
If cell.value = rowKey Then
row = cell.row
Exit For
End If
Next
If row = -1 Then
Exit Function
End If
column = -1
For Each cell In dataRange.Rows(1).Cells
If cell.value = columnKey Then
column = cell.column
Exit For
End If
Next
If column = -1 Then
Exit Function
End If
Set GetCell = dataRange.Cells(row, column)
End Function