tags:

views:

969

answers:

2

Hi,

I have a range of rows with a column with a formula I populated using ctrl-D. How can I insert a new line so values are blank but formulas are copied?

Thank you

+1  A: 

It sounds like you are looking for a "pastespecial--> formulas but not values" option. I'm pretty sure that isn't possible unless you use VBA.

You could try something like:

This will clear any cells that don't have formulas. It assumes you are in the left-most cell in the row when you call it, and that the row doesn't have any blank cells. If those assumptions aren't accurate, you'll need to tweak it to get it to work.

  Sub KeepFormulasInRow()
    Do Until ActiveCell.Value = ""
        If Left(ActiveCell.Formula, 1) <> "=" Then
            ActiveCell.Clear
        End If

        ActiveCell.Offset(, 1).Select
    Loop
 End Sub
Jon
thank you. could you please add a line or two about how to use this function? can i associate it with a button or shortcut?
IttayD
A: 

Add the code to your workbook:

  1. Alt-F11 to open the VB Editor
  2. Insert --> Module
  3. Paste the code

Associate it with a button:

  1. Add a button to a worksheet
  2. Associate the macro to the button
  3. If you have an activeX button, call your macro from the on_click event

Associate it with a shortcut:

  1. Alt-F8 to open the list of macros in your workbook
  2. Highlight the macro you want to associate with a short-cut
  3. Click the options button
  4. Create your shortcut
Jon