Excel_VBA_User
New Member
- Joined
- Feb 25, 2015
- Messages
- 9
Hi Everyone,
I'm working with an ever-growing spreadsheet that I'm using to parse weather data strings from the internet. At the moment the spreadsheet contains 100,000 lines of data and 50+ columns, each with Excel formulas like the following to extract key bits of data:
=IFERROR(IF(LEFT(J3,3)="---",TRIM(MID(J3,FIND(CHAR(1),SUBSTITUTE(J3," ",CHAR(1),2)),LEN(J3))),TRIM(MID(J3,FIND(CHAR(1),SUBSTITUTE(J3," ",CHAR(1),3)),LEN(J3)))),"")
This Excel formula looks at a data string cell J3 (down to J100,000) and removes a leading portion. The resulting substring is printed in cell K3. Here are two sample strings that I'm working with:
10Oct15 NASA1 2 Miami 23 23.5 25 26 27 28 28 27.9 27.8 29 .....
--- NASA15 12 Tampa 24 24 24 25 25.1 26.2 27 27.1 27.1 27.2 .....
The Excel formula generates the following desired results:
Miami 23 23.5 25 26 27 28 28 27.9 27.8 29 .....
Tampa 24 24 24 25 25.1 26.2 27 27.1 27.1 27.2 .....
Because each cell in my spreadsheet contains a similar Excel formula, the file is 100mb+ and very unstable. I have tried various techniques to reduce the file size but it keeps ballooning back up to 100mb+. I looked into VBA options and started by recording the following macro:
This code produces the correct result, but it writes the Excel formula into the cell. Hence, the ballooning file size issue remains. I'm looking for help/guidance to convert the above Excel formula into a VBA functions with nested IFs etc. that just prints the result in corresponding cell in column J. Once I have a better understanding of how to rewrite the Excel formula as a VBA, I'll be able to tackle the remaining formulas in my spreadsheet. Many thanks in advance for your help!!
I'm working with an ever-growing spreadsheet that I'm using to parse weather data strings from the internet. At the moment the spreadsheet contains 100,000 lines of data and 50+ columns, each with Excel formulas like the following to extract key bits of data:
=IFERROR(IF(LEFT(J3,3)="---",TRIM(MID(J3,FIND(CHAR(1),SUBSTITUTE(J3," ",CHAR(1),2)),LEN(J3))),TRIM(MID(J3,FIND(CHAR(1),SUBSTITUTE(J3," ",CHAR(1),3)),LEN(J3)))),"")
This Excel formula looks at a data string cell J3 (down to J100,000) and removes a leading portion. The resulting substring is printed in cell K3. Here are two sample strings that I'm working with:
10Oct15 NASA1 2 Miami 23 23.5 25 26 27 28 28 27.9 27.8 29 .....
--- NASA15 12 Tampa 24 24 24 25 25.1 26.2 27 27.1 27.1 27.2 .....
The Excel formula generates the following desired results:
Miami 23 23.5 25 26 27 28 28 27.9 27.8 29 .....
Tampa 24 24 24 25 25.1 26.2 27 27.1 27.1 27.2 .....
Because each cell in my spreadsheet contains a similar Excel formula, the file is 100mb+ and very unstable. I have tried various techniques to reduce the file size but it keeps ballooning back up to 100mb+. I looked into VBA options and started by recording the following macro:
Code:
Code:
Sub TestRecording()
'
Dim rowNum As Integer
Set UsedRng = ActiveSheet.UsedRange
LastRow = UsedRng(UsedRng.Cells.Count).Row
Range("K3").Select
Do Until ActiveCell.Row = LastRow + 1
ActiveCell.FormulaR1C1 = "=IFERROR(IF(LEFT(RC[-1],3)=""---"",TRIM(MID(RC[-1],FIND(CHAR(1),SUBSTITUTE(RC[-1],"" "",CHAR(1),2)),LEN(RC[-1]))),TRIM(MID(RC[-1],FIND(CHAR(1),SUBSTITUTE(RC[-1],"" "",CHAR(1),3)),LEN(RC[-1])))),"""")"
ActiveCell.Offset(1, 0).Select
Loop
End Sub
This code produces the correct result, but it writes the Excel formula into the cell. Hence, the ballooning file size issue remains. I'm looking for help/guidance to convert the above Excel formula into a VBA functions with nested IFs etc. that just prints the result in corresponding cell in column J. Once I have a better understanding of how to rewrite the Excel formula as a VBA, I'll be able to tackle the remaining formulas in my spreadsheet. Many thanks in advance for your help!!