format cells-vba

avishain

Board Regular
Joined
Dec 14, 2010
Messages
75
hello there,

got a table from A to K

in colomn A and J i got numbers formated as "Genearl".

the problem is that some of these numbers are formated as "Text" and in some cases there is a space at the begining of the number which are formated as text.

what i need is, a macro,that when i hit it will remove all spaces from the begining of the numbers (which are loctaed in colomn A and J) and i need that the whole colomns will be formated as General.


thanks
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
In cell M1 type in and fill down:
=TRIM(A1)

In cell N1 type in and fill down:
=TRIM(J1)

After that copy as values results into A and J columns.
 
Upvote 0
Hi

Try:

Code:
Sub Test()
With Application.Intersect(Activesheet.UsedRange,Range("A:A"))
  .NumberFormat = "General"
  .Replace " ",""
  .Formula = .Value
End With
With Application.Intersect(Activesheet.UsedRange,Range("J:J"))
  .NumberFormat = "General"
  .Replace " ",""
  .Formula = .Value
End With
End Sub
 
Upvote 0
Sorry misread, thought question was all columns between A and J inclusive

Try:
Code:
Sub Spud()
 
Dim i As Long, j As Long
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
For i = 1 To 10
    For j = 1 To Cells(Rows.Count, i).End(xlUp).Row
        With Cells(j, i)
            .Value = Trim(Cells(j, i))
        End With
    Next j
    Columns(i).NumberFormat = "General"
Next
 
With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
End With
 
End Sub
 
Last edited:
Upvote 0
thank u all,but it still isnt working.


nor trim neither replace have helped.....


its very strange cause when i count the number of digits with "Len" i got 3 digits eventhough there is a space at the begining followed by 3 digits,means i had to get "4" when counted the length ....right?
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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