VBA 96 well plates positions

Function IsValidPosition(position As Integer) As Boolean
    If 1 <= position And position <= 96 Then
        IsValidPosition = True
    Else
        IsValidPosition = False
    End If
End Function


Function GetCoordinateFromVerticalPosition _
            (verticalPosition As Integer) As String
    Dim row As Integer
    Dim rowString As String
    Dim column As Integer
    Dim returnValue As String
        
    rowString = "A"
    
    If IsValidPosition(verticalPosition) Then
        row = (verticalPosition - 1) Mod 8 + 1
        rowString = Chr(Asc(rowString) + row - 1)
        column = (verticalPosition - row) / 8 + 1
        returnValue = rowString & column
    Else
        MsgBox "Invalid position number." & _
                vbNewLine & vbNewLine & _
                "Allowed values are 1-96.", _
                vbCritical, "GetCoordinateFromVerticalPosition: Invalid input"
        returnValue = vbNullString
    End If
    GetCoordinateFromVerticalPosition = returnValue
End Function

Leave a Reply

Your email address will not be published. Required fields are marked *