Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

function to enter formula in cells down a column based on cell color

excel 2003 vba
routine needed:

I have a "sheet1" with lookup data for sheet "UnSolicated_Projects".
On sheet "UnSolicated_Projects"
I have Gray rows as seperator
RGB(194, 194, 194)

On sheet "UnSolicated_Projects"
In ColumnB STARTING IN B2(but not always on B2) I need a formula inserted.
=VLOOKUP(A2,Sheet1!$A$2:$CO$11628,74,FALSE)
evertime there is a gray row , Underneath the gray cell THE formlua TO BE ADDED:

caveat:
Sometimes I may have  4 gray lines in a row

so the first row may be B5
=VLOOKUP(A5,Sheet1!$A$2:$CO$11628,74,FALSE)
 
Either way I need this formula added to ColumnB below a Grayline if the cell background is "NoFill"
Until the end of the rows.

The number of rows will always be different for each execution of the sub routine.

Then execute the formula

Thanks
fordraiders







FormulaCodeSS.png
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Does column A always start with CRS for a total row?

Is the CRS name constant in column C?

If so you could an IF statement:
 =IF(LEFT($A2,3)="CRS",SUMIF($C$1:$C1,$C1,$B$1:$B1),VLOOKUP($A2,Sheet1!$A$2:$CO$11628,74,FALSE))

Copy down and then apply conditional formatting based on the CRS again for the total rows.

Thanks
Rob H
Avatar of Fordraiders

ASKER

Does column A always start with CRS for a total row?   YES

Is the CRS name constant in column C?  YES

But I need vba function...this needs to be automated via a sub routine...not manual please


Can I ask why it has to be vba if the formula is working?

The population of the formula down the column as the data expands could be automated if you wanted.
because my folks are using this sheet not me , and they do not do anything manual
WITHOUT HAVING TO WORRY ABOUT THE COLOR ROW.

this almost works
Application.ScreenUpdating = False
Sheets("UnSolicated_Projects").Select
Dim LastRow As Long
LastRow = Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
Range("B2:B" & LastRow).FormulaR1C1 = "=VLOOKUP(R[ACTIVECELL.ROW],Sheet1!$A$2:$CO$11628,74,FALSE)"
Application.CutCopyMode = False
Application.ScreenUpdating = True
this works.

Application.ScreenUpdating = False
Sheets("UnSolicated_Projects").Select
Dim LastRow As Long
Dim j As Integer
j = ActiveCell.Row
LastRow = Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
Range("B2:B" & LastRow).Formula = "=VLOOKUP(A2,Sheet1!$A$2:$CO$11628,74,FALSE)"
Application.CutCopyMode = False
Application.ScreenUpdating = True
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks