Table operations
Hello Everybody,
This is my first posting to the group after joining this forum a short while ago. I hope that my problem will be addressed by somebody. I am quite new to coding in VBA under Excel environment. I have a data file saved in txt format. It is comma delimited file and has data from GPS and another sensor. Each row of GPS data has information recorded in 15 columns($GPGGA,hhmmss.ss,ddmm.mmmm,n,dddmm.mmmm,e, q,ss,y.y,a.a,z,g.g,z,t.t,iii*CC). Corresponding to each GPS data, 5 rows of data is logged by the sensor. The data from the sensor spans 5 columns.
Now, i want to use Excel macro to do the following:
(i) Navigate to the folder containing the data,
(ii)Read the text file,
(iii) Find the average of five readings of the sensor and assign to each GPS observation.
Since i have limited exposure to writing codes, so could have been successful in writing only the folowing that help me navigate to the folder and load the data:
Sub opentextfiles()
Dim fName As String ' Defines that the file name is a string variable
fName = Application.GetOpenFilename(filefilter:="Text Files (*.txt),*.txt") ' select a textfile to be opened
If fName = "False" Then ' in case user cancels the subroutine
Exit Sub
End If
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fName, Destination:=Range("A1"))
.Name = "fName"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 65000
.TextFileStartRow = 16
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ")"
.TextFileColumnDataTypes = Array(1, 1, 1, 1,1,1,1,1,1,1,1,1,1,1,1)
.TextFileTrailingMinusNumbers = False
.Refresh BackgroundQuery:=False
End With
End Sub
The above results in importing the code that is in following order
GPS data1 col1 col2 ...........col15
Sensor data1 Col1 ............col5
sensor data2 Col1...............col5
.
.
Sensor data5 col1..........col5
GPS data2 Col1..............col15
Whereas, i want the data to look like the following
GPSCOl1..............GPScol15 SensorCol1(avg of 5 values)...SensorCol5(average of 5 values)
Please provide me the code to implement this. Thanks for your kind help in advance.
Paaji
David
|