Abhishek Tripathi
New Member
Hello friends, I am a beginner in VBA coding. Code which i have attempted consist of two parts (a) Data extraction and (b) Plotting of xy-scatter graph from extracted data. My objective of the coding is listed below:-
1.) Data Extraction :- In this part of code i am trying to extract data from text files having .RS extension kept in a folder, into an excel. I have tried to automate the folder pick up which contain the text file, along with creation of excel file which will be having the extracted data. Based on the number of text files in the folder the cells in excel file will get arranged automatically and data will be extracted. (With this portion of code i am having no problem and i am able to perform the desired function).
2.) Plotting of extracted data into xy-scatter graph :- In this portion of code my objective is to automate the plotting of extracted data on a chart (XY-scattersmooth). Say i am having 5 text file in my folder then my program will extract the data from each of the file and import/paste it into excel, so i have now 5 series to be plotted (This number 5 (Text file) is variable it can go from say 1 to 1000). So to paste all the series on same chart i have done looping. I am facing problem in assigning a variable range to .Values and .XValues as my series ranges are not fixed i can't use the "A2:A245" kind of syntax for defining range. Portion of code where i am facing problem is pasted below;
At first instance i had two separate codes for performing the above written objective perfectly, and its working where as when i am trying to combine the two codes to make a single code for performing both the tasks at a single click its showing absurd graph view.
Macros are attached along with for your reference.[/CODE]
1.) Data Extraction :- In this part of code i am trying to extract data from text files having .RS extension kept in a folder, into an excel. I have tried to automate the folder pick up which contain the text file, along with creation of excel file which will be having the extracted data. Based on the number of text files in the folder the cells in excel file will get arranged automatically and data will be extracted. (With this portion of code i am having no problem and i am able to perform the desired function).
2.) Plotting of extracted data into xy-scatter graph :- In this portion of code my objective is to automate the plotting of extracted data on a chart (XY-scattersmooth). Say i am having 5 text file in my folder then my program will extract the data from each of the file and import/paste it into excel, so i have now 5 series to be plotted (This number 5 (Text file) is variable it can go from say 1 to 1000). So to paste all the series on same chart i have done looping. I am facing problem in assigning a variable range to .Values and .XValues as my series ranges are not fixed i can't use the "A2:A245" kind of syntax for defining range. Portion of code where i am facing problem is pasted below;
Code:
'**************************************************************
' Chart plotting
sh1.Cells(4, d).Select
Set ch = ActiveWorkbook.Charts.Add
Set ch = ch.Location(Where:=xlLocationAsObject, Name:="NRS-Data")
With ch
.ChartType = xlXYScatterSmooth
End With
a = 4
b = 1
For z = 1 To count
k = sh1.Cells(Rows.count, 1).End(xlUp).Row
If k = 1048576 Then
k = 1
End If
'**************************************************************
' Problem in this section of code
' I want to assign the range to xaxis and yaxis
' Range here is variable
' How to correct it
Set xaxis = Range(Cells(a, b), Cells(k, b))
Set yaxis = Range(Cells(a, b + 1), Cells(k, b + 1))
Set s = ch.SeriesCollection.NewSeries
With s
.Values = yaxis
.XValues = xaxis
.Name = sh1.Cells(2, b).Value
' set other series properties
End With
b = b + 2
'**************************************************************
Next z
At first instance i had two separate codes for performing the above written objective perfectly, and its working where as when i am trying to combine the two codes to make a single code for performing both the tasks at a single click its showing absurd graph view.
Macros are attached along with for your reference.[/CODE]
Attachments
Last edited by a moderator: