rs232 connection, parsing data to columns

errtu

Board Regular
Joined
Sep 23, 2010
Messages
134
I am trying to retrieve data from a rs232 device. I want to change this code to put my data into column B not A

Also I want to add a line, so that the code won't run if the previous row has the A column empty (even though B , C, D might have data

Code:
[/COLOR][/SIZE][/FONT][/B]Sub GetSWData()

   Dim R As Long
   Dim X As Long
   Dim Chan As Long
   Dim NumFields As Long
   Dim vDat As Variant
   Dim sDat As String

   ' find the next empty row in Column A
   R = ThisWorkbook.Sheets("DDE").Cells(65000, 1).End(xlUp).Row + 1
      
   ' Establish DDE link to WinWedge on Com1
   Chan = DDEInitiate("WinWedge", "Com3")

   ' How many data fields are we retrieving from WinWedge?
   NumFields = 1

   ' Loop through all data fields defined in the Wedge :
   For X = 1 To NumFields

      ' Request the data from each field in the wedge
      vDat = DDERequest(Chan, "Field(" & CStr(X) & ")")

      ' Convert the data from a variant array data type to a string
      sDat = vDat(1)


      ' Place the data in cell location Row = R, Column = X
      ThisWorkbook.Sheets("DDE").Cells(R, X).Value = sDat
      
   Next
     
   
   DDETerminate Chan ' Close the DDE channel

   ' Insert a date/time stamp in the sheet in the same row as the data
   ThisWorkbook.Sheets("DDE").Cells(R, NumFields + 3).Value = Now

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Also I want to add a line, so that the code won't run if the previous row has the A column empty
... I think you need to explain this a little more clearly.
 
Upvote 0
... I think you need to explain this a little more clearly.

This macro adds lines to A and D, another one (not specified here) adds data to C. And yet another one adds to A. I dont want this macro to run if the previous row has the A field empty (meaning data was not added to it with the other macro). And I want to change the columns where this macro adds the lines. Instead of A and D, I want it to add them to B and D.

I hope that's a bit clearer, sorry :(
 
Last edited:
Upvote 0
errtu, may I ask what code you are using to get RS232 data?
I'm currently doing something similar and am getting the data but am having trouble with some USB-RS232 converters.

thanks,

EDIT: NVM. I know what program you're using XD
 
Last edited:
Upvote 0
errtu, may I ask what code you are using to get RS232 data?
I'm currently doing something similar and am getting the data but am having trouble with some USB-RS232 converters.

thanks,

EDIT: NVM. I know what program you're using XD

winwedge man, it rocks. though it is not the only one, you can use several more
 
Upvote 0
Is this premise right ... if the last cell in column C is greater ( lower down ) than the last cell in column A, then don't do the processing?

As for adding data to B and D instead of A and D, just change this:
Code:
ThisWorkbook.Sheets("DDE").Cells(R, X).Value = sDat
to be:
Code:
ThisWorkbook.Sheets("DDE").Cells(R, X+1).Value = sDat
 
Upvote 0
Is this premise right ... if the last cell in column C is greater ( lower down ) than the last cell in column A, then don't do the processing?

As for adding data to B and D instead of A and D, just change this:
Code:
ThisWorkbook.Sheets("DDE").Cells(R, X).Value = sDat
to be:
Code:
ThisWorkbook.Sheets("DDE").Cells(R, X+1).Value = sDat

Yes! that is exactly right
 
Upvote 0
So, how about this:
Code:
  ' find the next empty row in Column A
   R = ThisWorkbook.Sheets("DDE").Cells(65000, 1).End(xlUp).Row + 1
  ' find the next empty row in Column C
   X = ThisWorkbook.Sheets("DDE").Cells(65000, 3).End(xlUp).Row + 1
   If X > R Then Exit Sub
?
 
Upvote 0

Forum statistics

Threads
1,224,578
Messages
6,179,654
Members
452,934
Latest member
mm1t1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top