axonjacksn
New Member
- Joined
- Jun 16, 2011
- Messages
- 2
Hi, first time poster here.
I'm working on parsing iostat information (it's a unix command to get disk information). It provides disk information in bytes, but when it gets to 1000 bytes it changes it to KB. For example, I'll have a data point that says 900 which mean 900 bytes and then another data point that says 1.1K which is 1100 bytes. Excel doesn't understand what the "K" means so I have to do a search for all cells that have a number followed by a "K" and then strip the "." and "K" out and add two zeros so that I have an actual number.
My issue is that the code I have in VBA is taking a long time to execute. When I have a large file (60,000 lines) there are over 20,000 instances with "K." The code runs an average of 565 "K" replacements per minute which will translate this to about 35 minutes to complete.
I don't have a lot of experience coding VBA so I did a mishmash of macro recording and things I found online.
Can someone let me know how I can optimize my code to do a faster search/modify/replace?
Thanks!
Here is my code:
I'm working on parsing iostat information (it's a unix command to get disk information). It provides disk information in bytes, but when it gets to 1000 bytes it changes it to KB. For example, I'll have a data point that says 900 which mean 900 bytes and then another data point that says 1.1K which is 1100 bytes. Excel doesn't understand what the "K" means so I have to do a search for all cells that have a number followed by a "K" and then strip the "." and "K" out and add two zeros so that I have an actual number.
My issue is that the code I have in VBA is taking a long time to execute. When I have a large file (60,000 lines) there are over 20,000 instances with "K." The code runs an average of 565 "K" replacements per minute which will translate this to about 35 minutes to complete.
I don't have a lot of experience coding VBA so I did a mishmash of macro recording and things I found online.
Can someone let me know how I can optimize my code to do a faster search/modify/replace?
Thanks!
Here is my code:
Code:
Sub find_ks()
'
' find_ks Macro
'
Dim cellvalue As String
Dim cellsmallvalue As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Do While 1 = 1
Columns("C:Z").Select
Selection.Find(What:="K", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
cellvalue = ActiveCell.Value ' sets cell value to variable
cellsmallvalue = Right(cellvalue, 2) 'Pull the right two characters
cellsmallvalue = Left(cellsmallvalue, Len(cellsmallvalue) - 1) 'removes the last character "K"
cellvalue = Left(cellvalue, Len(cellvalue) - 3) ' removes last 3 characters from string
cellvalue = cellvalue & cellsmallvalue & "00" '3800
ActiveCell.FormulaR1C1 = cellvalue 'set value
Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub