Adding a Function to a cell when inserting a row from a macro

M

Mbarnes

I am trying to add a function to a cell that would be in a new line that I am
adding from a macro. See My macro (below). The marco is connected to a button
in the worksheet. When I click the button it adds a new line at the top under
the column headings. I have some titles and other wording in the top rows. In
each colum I have filled the cells and made lists, which are hidden, rows 5
through 16. I use those to create a drop down list when you enter in data on
the new row.

The worksheet is for budget tracking. In Column F is "Budgeted Cost", in the
next Column G is "Actual $ spent". In Column H, I am using the function:
=IF(F17<>"",IF(G17>F17,"Over","Under"),"").

It only looks at the row(17). I want it to go on each row and I don't want
to copy it to every row I want the macro to add it to the new row. I would
like it to reference the row that is being modified not row 17, so If there
is a change later to say G:50 it will change H:50

My function

=IF(G17<>"",IF(G17>F17,"Over","Under"),"")

currently does this:
1. it looks to see if anything is in column G: G17<>""
2. If column F has anything in it, it will check to see if column G (Actual
$ spent) is greater than Column F (Budgeted Cost)
3. If Column G > F it will display "Over" in Column H
4. If Column G < F it will display "Under" in Column H

My Macro:

Sub Addnewline()
' Addnewline Macro
'
' Adds a new line at the top of worksheet under the column titles
Rows("17:17").Select
Selection.Insert Shift:=xlDown
End Sub
 

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