Quote Originally Posted by Ajust View Post
Hello,

I am trying to use this excel code to take torque readings from a calibration unit. I can receive the data but it all goes into the A15 cell. I would like to modify this program so that after each torque reading it moves down a cell so I can effectively separate each torque reading. How would I go about modifying this code in order to achieve this? Thanks for the help this forum is awesome!

Hi, just looking at the code and thought I'd check if you managed to do what you were hoping to do. If you go to the Connect() function you can make the changes below to 1) Make it scroll to next row on each input and 2) Create a new string rather than the previous appending to old string behaviour.

Public Sub Connect()
Dim strSettings As String, strData As String
Dim intPortID As Integer
Dim lngStatus As Long
    
    strData = ""
    strSettings = ""
    Sheet1.Range("C15").Value = ""
    
    Dim rowout As Integer: rowout = 15                 <---------     Add a new Integer starting at 15 here, 15 is the row that it will appear in first
    
    
    With Sheet1
      
            strSettings = "baud=" & Left(.Range("D5").Value, Len(.Range("D5").Value) - 3) & " parity=" & Left(.Range("D7").Value, 1) & " data=" & .Range("D6").Value & " stop=" & .Range("D8").Value
           ' intPortID = Mid(.Range("D2").Value, 4, Len(.Range("D2").Value) - 3)       <-------  Ignore these changes, these are because the COM port dropdownt
            intPortID = 10                                                                                     <------- list won't populate on my machine so COM10 forced :D Bodge later
            lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), strSettings)
            
            If lngStatus = 0 Then
                MsgBox "Connection to " & .Range("D2").Value & " Established!"
                .Range("A64").Value = 1
                Do While .Range("A64").Value = 1
                    lngStatus = CommRead(intPortID, strData, 1)
                    If lngStatus > 0 Then
                        .Range("C" & rowout).Value = strData                <------ this line will output the data to the current "C" & rowout instead of C15 
                        rowout = rowout + 1                                         <------ increments rowout after each line is received,
                    End If
                    'Sleep 500
                    DoEvents
                Loop
            Else
                lngStatus = CommGetError(strError)
                MsgBox "Connection Failed. " & strError
            End If
       
    End With
    
End Sub
Quick bodge but it works for me on a 64-bit Windows 10 with Excel 2013