|  
                                             
	Mit folgender kleinen Änderung wird das erwartete Ergebnis auch tatsächlich erreicht: 
Option Explicit
 
Sub test()
    Dim values(5) As Byte
    values(0) = 25  '//00011001
    values(1) = 50  '//00110010
    values(2) = 100 '//01100100
    values(3) = 150 '//10010110
    values(4) = 200 '//11001000
    values(5) = 255 '//11111111
     
    '//erwartet: 001001001011011
    Debug.Print get_Bitsequenz(values(), 2, 3, 15)
End Sub
 
'//Parameter
'//values       | ein Array vom Typ Byte mit beliebiger Länge
'//startByte    | Gibt die Position des ersten auszuwertenden Bytes im Array an (0 basiert)
'//startBit     | Gibt die Position des ersten Bits im startByte an (1 basiert)
'//anzahlBits   | Anzahl der Bits, die zurückgegeben werden
Public Function get_Bitsequenz(ByRef values() As Byte, startByte As Integer, startBit As Byte, anzahlBits As Byte) As String
    If startByte > UBound(values()) Then
        MsgBox "'startByte' in Array nicht vorhanden.", vbExclamation
        Exit Function
    End If
     
    Dim sValues() As String
    Dim i As Integer
    Dim s As String
    ReDim sValues(UBound(values()))
     
    For i = 0 To UBound(values())
        sValues(i) = ByteToBit(values(i))
    Next i
     
    If Len(sValues(startByte)) < startBit Then
        MsgBox "'startBit' ist größer als die Bitlänge.", vbExclamation
        Exit Function
    End If
     
    i = startByte
    Do While Len(s) < anzahlBits And i <= UBound(sValues)
        If i = startByte Then
            s = s & Mid(sValues(i), startBit + 1, Len(sValues(i)) - startBit)
        Else
            s = s & sValues(i)
        End If
        i = i + 1
    Loop
     
    If Len(s) < anzahlBits Then
        MsgBox "Zu wenig Bits vorhanden.", vbExclamation
        Exit Function
    End If
     
    get_Bitsequenz = Left(s, anzahlBits)
End Function
 
Private Function ByteToBit(ByVal v As Byte) As String
    Dim s As String, e As Byte, i As Integer
    e = v
     
    Do While Not e = 0
        s = s & CStr(e Mod 2)
        e = CByte(Int(e / 2))
    Loop
    
    For i = 1 To 8 - Len(s)
        s = s & "0"
    Next i
     
    ByteToBit = StrReverse(s)
End Function
	Änderungen: 
	1. Das Auffüllen der führenden Nullen (vor StrReverse sind die Nullen angehängt) in Zeile 68-70 
	2. Da der Parameter "startByte" Null-Indiziert verwendet wird, sollte dies auch bei "startBit" so gemacht werden, daher die Anpassung in Zeile 44 
     |