2 questions

alokjain22

New Member
Joined
Sep 15, 2006
Messages
1
I am good in excel. However i do not know how to solve the following two problems:-

1. Say i have a formula in Column C = "ColumnA+ColumnB (a1+b1, a2+b2, ... like that in all rows of column C. Now i want to add an 'IF' condition in the same row. (e.g.=if(a1+b1>100,100,a1+b1). One way of doing is entering this formula and copy it in all rows of col C. But what if Column C have different formulas, and i have to add the 'IF' condition (or any ther thing) in all rows of col C irrespective of difference of formulas.

2. In a Macro, how to choose the End of the sheet, when it is not a fixed cell?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this:

Code:
Sub Test()
    Dim Sh As Worksheet
    Dim Rng As Range
    Dim Cell As Range
    Set Sh = Worksheets("Sheet1")
    With Sh
        Set Rng = .Range("C1:C" & .Range("C" & .Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeFormulas)
    End With
    For Each Cell In Rng
        With Cell
            .FormulaR1C1 = "=IF((RC[-2]+RC[-1])>100,100," & Replace(.FormulaR1C1, "=", "") & ")"
        End With
    Next Cell
End Sub

In the sixth line, this:

.Range("C" & .Rows.Count).End(xlUp)

returns the last used cell in column C.
 
Upvote 0
Hi Andrew

I was thinking that instead of

Replace(.FormulaR1C1, "=", "")

maybe

Mid(.FormulaR1C1, 2)

in case the formula has other "=" besides the first.

Cheers
PGC
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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