ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to input formula in range based on another range (https://www.excelbanter.com/excel-programming/279090-macro-input-formula-range-based-another-range.html)

Peter Atherton

Macro to input formula in range based on another range
 
Try this - make sure that the names column is selected
before it is run. It assumes that the range starts in row
1 with the data in row 2.

Sub fillFormulas()
Dim rng As Range
Dim i As Integer, r As Integer

'activecell should be in the names column
r = ActiveCell.CurrentRegion.Rows.Count
col = ActiveCell.Column
For i = 2 To r
Cells(i, col + 1).Formula = "=SUM(RC[-6]:RC[-2])"
Next i
End Sub

Regards
Peter
-----Original Message-----
Hi folks, here is my problem. I have a column of names

(may be in any
column depending on the workbook, but lets assume col B)

with an empty
column to the right of it(col C) .

I want to write a macro that will input a formula in each

cell of
column C if there is a name in the corresponding cell of

col B. There
will be no blank cells in col B so the first blank cell

will be at the
end of the list and should stop the macro.

Can anyone help with some code ideas? Thanks.:)



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from

http://www.ExcelForum.com/

.



All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com