Hi,
Could someone please tell me how to copy a text string from a cell in Excel and paste in to another minus the last two characters in VBA?
For example if my original cell was 333.2cm, I would like the pasted cell to be 333.2
Thanks
Hi,
Could someone please tell me how to copy a text string from a cell in Excel and paste in to another minus the last two characters in VBA?
For example if my original cell was 333.2cm, I would like the pasted cell to be 333.2
Thanks
Assuming your cell is formatted as text, otherwise fix the formatting.
For Each cel In Selection cel.Offset(, 1) = Left(cel, Len(cel) - 2) Next
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
mdmackillop,
That's great thanks. I have used:
There will be up to 8 fields with the data in but not always. How do I stop it throwing up an error when if one of those cells are empty?Sub Button1_Click() Range("D3,D10,D17,D24,D31,D38").Select For Each cel In Selection cel.Offset(, 8) = Left(cel, Len(cel) - 3) Next End Sub
Thanks
Last edited by mdmackillop; 09-13-2017 at 03:59 AM. Reason: Code tags added
Avoid selecting, refer to ranges directly
Please use code tags when yoiu post codeSub Button1_Click() For Each cel In Range("D3,D10,D17,D24,D31,D38") If Len(cel) > 3 Then cel.Offset(, 8) = Left(cel, Len(cel) - 3) Next End Sub
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'