title: Convert string to binary in excel vba
body: <p><strong>This is my code where I try to convert string to binary but its not working.Can please somebody help me? I have been trying to solve this for past 5 days!!
  Thank you in advance!</strong>     </p>
  
  <pre><code>  Sub Button1_Click()
            Dim strText As String
             strText = ActiveWorkbook.Sheets("Sheet2").Range("A1")
  
             Debug.Print strText
             Dim n, val As Integer
             n = Len(strText)
  
             Debug.Print n
  
             Dim str As String
              str = Mid(strText, 1, 1)
             Debug.Print str
             For i = 1 To n
             'val = CInt(strarr(i))
             val = Asc(str)
  
             Debug.Print val
             Dim bin As String
             Dim modval As Integer
             bin = ""
  
             While val &gt; 0
             modval = val - (2 * (val \ 2))
  
             If modval = 1 Then
             bin = bin &amp; "1"
             val = 0
             Else
             bin = bin &amp; "0"
             val = 0
             End If
             Wend
  
             bin = StrReverse(bin)
             Debug.Print bin
             Next i
             Debug.Print i
              ActiveWorkbook.Sheets("Sheet2").Range("A2") = bin
          End Sub
  </code></pre>