Removing the first character using VBA

NELMO

New Member
Joined
Jun 7, 2005
Messages
9
I posted an earlier question about an Access query export to Excel putting leading apostophe (') before all data.
To remove them I thought I would use Find/Replace but the Apostophe is not recognised!

Is there a way (programmatically) to remove the first character of each data entry in each cell in a column?

thanks in advance

nel
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Indeed

You can iterate through each cell in the column and say:

Code:
Sub test()

x = 1
Do Until Cells(x, 1) = ""
Cells(x, 2) = Mid(Cells(x, 1), 2, Len(Cells(x, 1)) - 1)
x = x + 1
Loop

End Sub

This presumes we are going from cell A1, down a non-interrupted list.

Hope this helps

Patrick
 

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good afternoon NELMO

How about something like this :

Code:
Sub Test()
For Each UsrCell In Selection
UsrCell.Value = Right(UsrCell.Value, Len(UsrCell.Value))
Next UsrCell
End Sub

Just highlight the range you want to remove the first character from and run the macro.

HTH

DominicB
 

NELMO

New Member
Joined
Jun 7, 2005
Messages
9
code works

Thats perfect

:p thanks DominicB

Sorry Andrew, :oops: didn't know whic to post too

Nel
 

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Two things that annoy me about this board:

1) People asking questions which have been asked hundreds, if not thousands of times in the million odd posts that exist here

2) People that do not thank everyone who contributes an answer. People dont answer these questions for their own health, or any financial reward. It's the least you could do.
 

Forum statistics

Threads
1,141,098
Messages
5,704,319
Members
421,338
Latest member
Pepess

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top