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
Printable View
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.
Code:For Each cel In Selection
cel.Offset(, 1) = Left(cel, Len(cel) - 2)
Next
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?Code: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
Avoid selecting, refer to ranges directly
Please use code tags when yoiu post codeCode:Sub 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