remove spaces and points in cells with vba

already

Board Regular
Joined
Nov 11, 2008
Messages
179
Hi

I have to remove space and/or points from cells with a VAT number , IBAN and swift in exel sheets. (3 or 4 cells on the sheet) How can I do this with VBA.

Thanks in advance for your help

Regards

Al
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Record a macro to use things like trim and find/replace to remove the unwanted characters.

Maybe easier to help if you could show sample data.
 
Upvote 0
Hi Trevor,
Thanks for your reply. Recording the macro seems not to work in this case. (have already tried)

sample data:

vat number in cell D2 NL123 123 123 should be converted in NL123123123
iban in cell D4 NL 123.123 123 should be converted in NL123123123
etc

Kind regards

Al
 
Upvote 0
I can't see why a macro wouldn't do the job, but have you considered doing a FIND and REPLACE for each cell ?
 
Upvote 0
Hi this is my first post to MR. excel board, i hope it will work and help

create this funcition in VBA

Function SuperTrim(Entry)
For i = 1 To Len(Entry)
ThisChar = Mid(Entry, i, 1)
Select Case Asc(ThisChar)
Case 32, 46
Case Else
SuperTrim = SuperTrim & ThisChar
End Select
Next i
End Function


then use this in worksheet =SuperTrim(A4) :)
 
Upvote 0
Hi rustam and Welcome to the Board !!
I'm pretty sure it doesn't happen very often, that somebody's first post is an answer !!
Well done ! nice work !!
 
Upvote 0
Hi Rustam,

Thanks for your solution. But in this case I can't use a function.

I'm collecting many documents based on a template from my colleagues with the data in the wrong format. I may not change the template with the required format. So I'm looking for a macro to change the 4 cells to the required format.

Kind regards

Al
 
Upvote 0
Hi Rustam,

Thanks for your solution. But in this case I can't use a function.

I'm collecting many documents based on a template from my colleagues with the data in the wrong format. I may not change the template with the required format. So I'm looking for a macro to change the 4 cells to the required format.

Kind regards

Al

Here is a snippet I use often. Can you use it?

Code:
LASTROW = Cells(Rows.Count, 1).End(xlUp).Row

Range("D2:D" & LASTROW).Replace What:=".", Replacement:="", LookAt:=xlPart, _
     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
     ReplaceFormat:=False

Range("D2:D" & LASTROW).Replace What:=" ", Replacement:="", LookAt:=xlPart, _
     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
     ReplaceFormat:=False
 
Upvote 0

Forum statistics

Threads
1,216,182
Messages
6,129,364
Members
449,506
Latest member
nomvula

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
Back
Top