OT: Excel macro help

g.mccormick

Lifetime Supporting Member
Join Date
Jul 2012
Location
IN
Posts
961
Since this is a large collection of very smart people, hopefully someone here can help out my dumb self.
I have an excel sheet that has 3 columns of data.
The first columns is number of points, second column is setpt A, and third is setpt B. So for example if the first row has:
3, 10, 5 I need to copy that data to 3 rows with each row being 10, 5. The number of points can be 1 to perhaps 50, so the number of rows copied will be different. What whould I need to do in a VBA script to copy this data? I've attached a picture of what I have and the end result needs to be. Thanks

ExcelHelp.png
 
Paste this code into excel VBA. It's quick and dirty but it worked once in a row. Which is as many times as I tested it.
Sub Setpoints()


Dim Num_Point_array(100, 100, 100)
Dim x, y, z As Integer
Dim Num_points As Integer
Dim Setpt_A As Integer
Dim Setpt_B As Integer
Dim StartRow As Integer
Dim index As Integer
Dim lRow As Long

z = 1
'Find the last non-blank cell in column A(1)
lRow = Cells(Rows.Count, 1).End(xlUp).Row

StartRow = lRow + 5 ' start about 5 down from the end
index = 1
For x = 2 To lRow
Num_points = Cells(x, 1).Value
Setpt_A = Cells(x, 2).Value
Setpt_B = Cells(x, 3).Value

For y = 1 To Num_points
Cells(StartRow, 1).Value = index 'point number
Cells(StartRow, 2).Value = Setpt_A
Cells(StartRow, 3).Value = Setpt_B
index = index + 1
StartRow = StartRow + 1

Next y


Next x


End Sub
 
No problem. If this were something you were going to use a lot I would build the macro to put the results on a separate sheet or another workbook and of course put in a button to initiate it.
 

Similar Topics

Hello. For a PLC data logging application at a candy factory, a customer requested me to setup an add-in for MS Excel called "MX Sheet" which is...
Replies
22
Views
7,978
I have not been able to crack this one out, even after much thinking and googling:banghead:. I would be so grateful if I can get some guidance...
Replies
11
Views
3,679
I am using a tag through RSlinx to trigger a macro in an excel spread sheet. When the tag goes high I want to log the date and time into a column...
Replies
4
Views
2,193
Hi Everyone, I am currently trying to collect data from Siemens PLc S7-300 with Excel using Libnodave.dll With the exemple of program from the...
Replies
1
Views
3,393
I am taking data from a AB PLC and recording it in excel. When a certain time is reached the macro prints to pdf and then should close out...
Replies
0
Views
3,043
Back
Top Bottom