Solved

Remove all formulas in column of active cell.

Posted on 2013-12-20
5
406 Views
Last Modified: 2013-12-22
This code changes the formulas to ValuesAndNumberFormats on Col A.
How would I convert this to work on whatever column the active cell is in?  To capture however many cell in that column has a formula in it...  I do not believe there will be any spaces.

Plan is to use this in multiple places in a project.  Please advise and thanks. -R-

Sub CopySpecialPasteValuesAndNumberFormats()
'
' CopySpecialPasteValuesAndNumberFormats Macro
' Need to change this to whatever the column is of the active cell
' For reuse throughout the workbook
'
    Columns("A:A").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

Open in new window

0
Comment
Question by:RWayneH
5 Comments
 
LVL 32

Expert Comment

by:Rob Henson
ID: 39731658
Line 7, Rather than

Columns("A:A).Select

Use

C = Activecell.Column
Cells(1,C).Select
ActiveCell.EntireColumn.Select


The first two lines ensure you are in row 1 when copy/pasting.
Thanks
Rob H
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39731662
change columns("A:A").select to

ActiveCell.EntireColumn.Select

if you just want a single column

Change to
Selection.EntireColumn.Select


if you want all the columns in a multiple select.

NB: watch out for merged cells!

Reg
0
 
LVL 32

Assisted Solution

by:Rob Henson
Rob Henson earned 250 total points
ID: 39731677
Or using similar method to earlier suggestion, assuming no blank cells as per question:

C = Activecell.Column
Cells(1,C).Select
Do Until Cell.Value = ""
Cell.Value = Cell.Value
ActiveCell.Offset(1,0)
Loop

This will overwrite formulas with values and/but will leave formatting alone.

Thanks
Rob H
0
 
LVL 81

Accepted Solution

by:
byundt earned 250 total points
ID: 39732109
You could also remove the formulas with this one-liner:
Sub CopySpecialPasteValuesAndNumberFormats()
ActiveCell.EntireColumn.Formula = ActiveCell.EntireColumn.Value
End Sub

Open in new window

0
 

Author Closing Comment

by:RWayneH
ID: 39735106
Thanks -R-
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will show you how to use shortcut menus in the Access run-time environment.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now