xcaliber13 Posted September 12, 2016 Share Posted September 12, 2016 Ok it's Monday Morning and I am just at a complete blank to do this: I have an excel column that should only have numbers in each cell. Always a 4 digit number. But some of the cells get pulled into excel with letters in this column. Can someone point in the direction I should look to? Cells look like this: LLE 2256 N M 2267 M 2298 Need them to look like this: 2256 2267 2298 Basicly delete the letters, keep the numbers. Just totally blank on how to begin. Thanks Link to comment Share on other sites More sharing options...
xcaliber13 Posted September 12, 2016 Author Share Posted September 12, 2016 Ok so I have tried this: For $i = 1 To $iLastRow $iCell = _Excel_RangeRead($oWorkbook, Default, "H" & $i) If $iCell > "" Then StringRegExpReplace($iCell, "[A-Za-z]", "") Next This code does not work. Is this not a regex problem? Should I look to do something else? Thank you Link to comment Share on other sites More sharing options...
water Posted September 12, 2016 Share Posted September 12, 2016 Define "Does not work". How do you know that it doesn't work? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AutoBert Posted September 12, 2016 Share Posted September 12, 2016 the result is never written back to the excel cell. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 12, 2016 Moderators Share Posted September 12, 2016 StringRegExpReplace doesn't inherently know what you want to do with the returned value. Have you tried something like: _Excel_RangeWrite($oWorkbook, Default, StringRegExpReplace($iCell, "[A-Za-z]", ""), "H" & $i) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
xcaliber13 Posted September 12, 2016 Author Share Posted September 12, 2016 OK! Thank you everyone for getting me on the right Track. I got it to work. This works: For $i = $iLastRow To 1 Step -1 $iCell = _Excel_RangeRead($oWorkbook, Default, "H" & $i, 3) $sCell = StringRight($iCell, 4) _Excel_RangeWrite($oWorkbook, Default, $sCell, "H" & $i) Next Again a big thank you all Link to comment Share on other sites More sharing options...
water Posted September 12, 2016 Share Posted September 12, 2016 If performance is an issue then I suggest to use _Excel_RangeRead to read the whole column in one go into an array, modify the array and then rewrite the whole column from the array. That's much faster! My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
xcaliber13 Posted September 12, 2016 Author Share Posted September 12, 2016 Water, Would I then use _ArrayTrim? Link to comment Share on other sites More sharing options...
water Posted September 12, 2016 Share Posted September 12, 2016 If you have always to remove the same number of characters from the left then _ArrayTrim could be a solution. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now