Could someone please code me an algorythm to erase the last 2 characters in a cell value?
EX: cell A1 has this: "hello world". I want cell A1 to have "hello wor"
How would I go about doing this? Snippets would be nice.
Thanks
Could someone please code me an algorythm to erase the last 2 characters in a cell value?
EX: cell A1 has this: "hello world". I want cell A1 to have "hello wor"
How would I go about doing this? Snippets would be nice.
Thanks
Last edited by LodBot; Nov 7th, 2003 at 03:48 PM.
Use the Mid and Len functions like so...
VB Code:
A1 = Mid(A1, 1, Len(A1) - 2)
VB/Office Guru™ (AKA: Gangsta Yoda™®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Star Wars Gangsta Rap • Reps & Rating Posts • VS.NET on Vista (New) • Multiple .NET Framework Versions (New) • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
VB Code:
rowCount = 2 While (Range("C" & rowCount).Value <> "") Range("C" & rowCount).Value = Mid(Range("C" & rowCount).Value, 1, (Len(Range("C" & rowCount).Value) - 2)) rowCount = rowCount + 1 Wend
When I run this code, I get an error saying "Run Time Error '5': Invalid procedure call or argument"
I'm coding in Excel if it matters.
Thanks
It looks like you may need to trap for when the cell only has 1 or
2 characters. When you subtract 2 from 1 or 2 you get a negative
number. Invalid Procedure call or argument.
VB Code:
rowCount = 2 While (Range("C" & rowCount).Value <> "") If Range("C" & rowCount).Value > 2 Then Range("C" & rowCount).Value = Mid(Range("C" & rowCount).Value, 1, (Len(Range("C" & rowCount).Value) - 2)) Endif rowCount = rowCount + 1 Wend
VB/Office Guru™ (AKA: Gangsta Yoda™®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (VBA, VB 6, VB.NET, C#)
Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Star Wars Gangsta Rap • Reps & Rating Posts • VS.NET on Vista (New) • Multiple .NET Framework Versions (New) • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 150 GB HDs RAID 1, 2 GBs DDR2 667 MHz RAM, 3 Viewsonic 17" LCDs, Windows Vista RTM, IE 7, Office 2007
problem solved
Thanks for the quick reply