VBA code that will reapply my formula to the specific range of cells

glenn0004

New Member
Joined
Nov 15, 2011
Messages
18
Hi All

I have an ongoing requirement that I'm trying to resolve within a sales order workbook. If Sales person has agreed a fixed price for subsequent sales order lines they enter the price in to sheet 1, and the pricing is pulled through to each order line on sheet 2. However if the Sales person has not agreed a fixed price for subsequent sales order line they manually enter the price in to the second sheet and overwrite the formula that was originally pulling through the price.

My problem is now that the formula is overwritten and the workbook is now erroneous if reused to create another order as some order lines will contain the will contain the formula and some will not. Is there a VBA code that will reapply my formula to the specific range of cells that the user can run.

Many thanks in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi All

I have an ongoing requirement that I'm trying to resolve within a sales order workbook. If Sales person has agreed a fixed price for subsequent sales order lines they enter the price in to sheet 1, and the pricing is pulled through to each order line on sheet 2. However if the Sales person has not agreed a fixed price for subsequent sales order line they manually enter the price in to the second sheet and overwrite the formula that was originally pulling through the price.

My problem is now that the formula is overwritten and the workbook is now erroneous if reused to create another order as some order lines will contain the will contain the formula and some will not. Is there a VBA code that will reapply my formula to the specific range of cells that the user can run.

Many thanks in advance.
Hi glenn,

Yes that is certainly possible. If you can give an example of the formula and define the range it needs to be applied to, it will be easier to help tailor the code for you.
 
Upvote 0
Hi glenn,

Yes that is certainly possible. If you can give an example of the formula and define the range it needs to be applied to, it will be easier to help tailor the code for you.

Hi,

The formula I need applying are as follows:

Summary T31:T52 =IF(AND(Contract!$C$61<>"",Summary!E32="MFD"),Contract!$C$61,"")

Summary W31:W52 =IF(AND(Contract!$F$61<>"",Summary!E31="MFD"),Contract!$F$61,"")

Summary Z31:Z52 =IF(AND(Contract!$I$61<>"",Summary!E31="MFD"),Contract!$I$61,"")

Summary AC31:AC52 =IF(AND(Contract!$L$61<>"",Summary!E31="MFD"),Contract!$L$61,"")

One problem area that I have, is that addition lines can be added to the above ranges.

Hope that you can still help
 
Upvote 0
addition lines can be added to the above ranges
So is the cell reference going to be the last row of data ?
for example, I'm guessing data will be input into other columns and then this formula will have to match those rows of data ??
 
Upvote 0
So is the cell reference going to be the last row of data ?
for example, I'm guessing data will be input into other columns and then this formula will have to match those rows of data ??

Unfortunatly Not:

A new row could be entered anywhere after row 31, the worksheet is set up for 21 rows as default. Yes data is entered into a set of cells in worksheet called contract (C61 F61 I61 L61), each of cells within the range on the Summary worksheet then need to pull through C61 F61 I61 L61 from the contracts worksheet respectivley.

Thanks in adavnce
 
Upvote 0
Hi Glenn,

I wonder if a different approach might be better. Your comment
the workbook is now erroneous if reused
suggests that you could use a template which would allow New workbooks to be created that are clean.

Just a thought.

Regards
 
Upvote 0
@Peter
....and a good thought at that...(y)

Hi All
Yes, we have thought about this. However we are wary that the users are sales people (and sorry to tar all sales people)and very likley to revert to a previous completed worksheet and overtype the data.

I'm keeping this in the bag as a last resort.

Regards
 
Upvote 0
Understand that issue - getting users to behave is a challenge, even if you give them a userguide!!

Given that you're happy using VBA, would using conditional formating to highlight non-computed cells be helpful?

If so, enter this as a function in VBA:

Code:
Function isFormula(aCell As Range) As Boolean
    If Left(aCell.Formula, 1) = "=" Then
        isFormula = True
    Else
        isFormula = False
    End If
End Function

Then use: =NOT(isFormula(A1)) as the CF Formula.

Just a thought.

Regards
 
Upvote 0
@pjmorris
Could your function be shortened to :-
Code:
Function isFormula(aCell As Range) As Boolean
    isFormula = (Left(aCell.Formula, 1) = "=")
End Function

hth
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,861
Members
449,472
Latest member
ebc9

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