code not looping.

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
hi all - i thought this code would loop through the range and put a formula in every box ... but it doesn't. how can it be changed to make it loop?

Code:
    With Range("E2:E100").Find("Z004").Offset(0, 10)
        .Value = "=((K3*M3)/N3)"
    End With

if it is possible, can the code just loo for Z00 rather than Z004.... i could use that to fill the rest of the column rather than have separate codes for each....

thank you :)
 
VBA Code:
Sub enterformula()

Dim x As Long
Dim lr As Long
Dim c As Range

lr = Range("E" & Rows.Count).End(xlUp).Row

    For Each c In Range("E3:E" & lr)
        If c.Value = "CONV" Then
            c.Offset(0, 10).Formula = "=((RC[-4]*RC[-2])/RC[-1])"
        End If
    Next c
   
End Sub
that code works for me when running just CONV.... thank you immensely.

just a side question, where can i get info on the R1C1 formulas? lol...... i'll hit up google i think
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Do you need to find only one specific value in column E, or more than one ?
 
Upvote 0
Do you need to find only one specific value in column E, or more than one ?

Hi footoo.... it's a little hard to explain.

I need to find all the values but not every value will have the same formula. the code i was given earlier has done what i need it to do. :)
 
Upvote 0
Hi footoo.... it's a little hard to explain.

I need to find all the values but not every value will have the same formula. the code i was given earlier has done what i need it to do. :)
Just thought you might want to have one macro only.
 
Upvote 0
if you're up for the challenge please feel free lol. one would be good
Post the values you want to find in column E together with the formula required for each value.
 
Upvote 0
Post the values you want to find in column E together with the formula required for each value.

hi footoo... here is the table i'm working with.
formula that goes into column O: =((K3*M3)/N3) row number needs to change as it fills down
happy if code looks for any of these values and if found inserts formula: Z004, Z003, Z002, CONV
sum total is always 5 cells to right of 'total raw and pack cost cell
sum total not always in the same cell in column O

COGs runner.xlsm
EIJKLMNO
1Total Manufactured Cost
2Material TypeResourceResource TextQuantityBase UoMPriceBase UnitZero BoM
3Z003RA001003-1.394KG$2,530.001000-$3.53
4Z003RA0010031.394KG$2,530.001000$3.53
5Z00310003106354.06KG$3,050.001000$1,079.88
6Z002SA000450521.174KG$3,987.051000$2,077.95
7Z003RA001003-1.046KG$2,530.001000-$2.65
8Z003RA0010031.046KG$2,530.001000$2.65
9Z003RA0010110.774KG$13,650.001000$10.57
10Z003RA00103031.645KG$4,407.001000$139.46
11Z003RA0012561.165KG$32,499.341000$37.86
12Z003RA0012602.326KG$2,450.001000$5.70
13Z003RA0016726.537KG$397.801000$2.60
14Z002SA0012121227.393KG$1,468.241000$1,802.11
15Z004PA0297516122.4EA$16.431000$100.59
16Z004200614226060.6EA$78.311000$474.61
17Z004200614146060.6EA$45.811000$277.64
18Z004200614231010.1EA$392.001000$395.96
19Z004PA0217002040.8EA$7.551000$15.41
20Z004PA02759610.677EA$530.401000$5.66
21Total Raw & Pack Cost$6,426.00
Layout
Cells with Conditional Formatting
CellConditionCell FormatStop If True
O21:O22Expression=$J20="Total Raw & Pack Cost"textNO
O21:O22Expression=$J20="Total Conversion Cost"textNO
O21:O22Expression=$J20="Total Manufactured Cost"textNO
V3:V103,A3:P20,A24:P103,A21:I23,K21:P23Expression=$E3="CONV"textNO
K3:K103,V3:V103,O3:O103Expression=$K3="Unit Price"textNO
K3:K103,V3:V103,O3:O103Expression=$K3="Total"textNO
K3:K103,V3:V103,O3:O103Expression=$K3="Conversion"textNO
K3:K103,V3:V103,O3:O103Expression=$K3="Raw"textNO
K3:K103,V3:V103,O3:O103Expression=$K3="pack"textNO
A3:V20,A24:V103,A21:I23,K21:V23Expression=$E3="Z002"textNO
A3:V20,A24:V103,A21:I23,K21:V23Expression=$E3="Z003"textNO
A3:V20,A24:V103,A21:I23,K21:V23Expression=$E3="Z004"textNO
J24:J103,J3:J22,O24:O103,O3:O20,V24:V103,V3:V20Expression=$J3="Total Raw & Pack Cost"textNO
J24:J103,J3:J22,O24:O103,O3:O20,V24:V103,V3:V20Expression=$J3="Total Conversion Cost"textNO
J24:J103,J3:J22,O24:O103,O3:O20,V24:V103,V3:V20Expression=$J3="Total Manufactured Cost"textNO
J21:J22Expression=$E23="CONV"textNO
J21:J22Expression=$E23="Z002"textNO
J21:J22Expression=$E23="Z003"textNO
J21:J22Expression=$E23="Z004"textNO
O21:O22,V21:V22Expression=#REF!="Total Raw & Pack Cost"textNO
O21:O22,V21:V22Expression=#REF!="Total Conversion Cost"textNO
O21:O22,V21:V22Expression=#REF!="Total Manufactured Cost"textNO
 
Upvote 0
You wrote previously that each value requires a different formula. I see that is not the case, so :
VBA Code:
Sub enterformula()
Dim ray: ray = Array("Z002", "Z003", "Z004", "CONV")
[E:E].AutoFilter Field:=1, Criteria1:=ray, Operator:=xlFilterValues
Dim lr&: lr = Cells(Rows.Count, "E").End(3).Row
If lr > 2 Then Range("O3:O" & lr).SpecialCells(xlCellTypeVisible) _
    .FormulaR1C1 = "=RC[-4]*RC[-2]/RC[-1]"
[E:E].AutoFilter
End Sub
 
Upvote 0
You wrote previously that each value requires a different formula. I see that is not the case, so :
VBA Code:
Sub enterformula()
Dim ray: ray = Array("Z002", "Z003", "Z004", "CONV")
[E:E].AutoFilter Field:=1, Criteria1:=ray, Operator:=xlFilterValues
Dim lr&: lr = Cells(Rows.Count, "E").End(3).Row
If lr > 2 Then Range("O3:O" & lr).SpecialCells(xlCellTypeVisible) _
    .FormulaR1C1 = "=RC[-4]*RC[-2]/RC[-1]"
[E:E].AutoFilter
End Sub

yeah i think i was thinking of another column or just not described what i was after properly.... thank you :)
 
Upvote 0
yeah i think i was thinking of another column or just not described what i was after properly.... thank you :)
It occurs to me that what you might want is to put the formula in column O in every row where column E contains any value.
If so, the code can be much simpler :
VBA Code:
Sub enterformula()
Range("O3:O" & Cells(Rows.Count, "E").End(3).Row) _
    .SpecialCells(xlCellTypeConstants).FormulaR1C1 = "=RC[-4]*RC[-2]/RC[-1]"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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