Insert a function in an entire column

E

Emece

I have a column with many values, and I need to add the int function to the
entire column. I cannot create another column, obtain the int value and
delete the first column because there are several other cells in the workbook
referring to the original column.

Is there a way to insert the function in the column?

Thanks in advance

Regards
Emece
 
G

Gary''s Student

Select the cells whose formulas you want to modify and run this simple macro:

Sub INT_Only()
' gsnuxx
s1 = "=INT("
s2 = ")"
For Each r In Selection
If IsEmpty(r) Then
Else
v = r.Formula
If Left(v, 1) = "=" Then
v = Right(v, Len(v) - 1)
End If
r.Formula = s1 & v & s2
End If
Next
End Sub
 
B

Bernard Liengme

You have some numbers on Sheet 1 in column, say, J like 12.34, 456.67 and
you want =INT(12.34) etc? Would you be happy with a process that converts
12.34 to 12 and 456.67 to 456 etc?

On another sheet (say Sheet4) in J1 enter =INT(Sheet1!J1) and copy down the
column as far as needed.
Select all these formulas and Copy
Move to J1 in Sheet1 and use Edit | Paste Special with Values specified.
Now you have integers
best wishes
 
D

Dave Peterson

Instead of using:
v = Right(v, Len(v) - 1)

You could use:
v = mid(v, 2)

(VBA's mid doesn't need that third parm. It's different than excel's =Mid().)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top