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 :)
 
the second code is definitely almost there... thank you... it's just one row out. the formula starts in E3 in all cases.....
i missed the line o2.. changed to O3.. been looking at this way too long today!
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
I think your Column E2:E100 is not a fixed range and could go below that.
In that case, Try this

VBA Code:
Sub enterformula()

Dim x As Long
Dim lr As Long

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

    x = Range("E2:E" & lr).Find(WHAT:="Z00", LookAt:=xlPart, SearchDirection:=xlPrevious).Row
  
    Range("O2:O" & x).Formula = "=((K3*M3)/N3)"
  
    End Sub
if i wanted to aim the code specifically at Z003 can i just change Z00 to Z003?
 
Upvote 0
yes, absolutely.
if i change it to Z003 it fills the rows in column E that have Z004 in them...... but excludes any line with Z002
if i put Z002 in the code it fills all rows that have Z00 in it.
 
Upvote 0
Shouldn't happen like that if you have given proper references.

However, you can try changing this line :
x = Range("E2:E" & lr).Find(WHAT:="Z00", LookAt:=xlPart, SearchDirection:=xlPrevious).Row

To this line
x = Range("E2:E" & lr).Find(WHAT:="Z00", LookAt:=xlwhole, SearchDirection:=xlPrevious).Row

After making changes in the code if problem persists, just paste your entire code here so that the members can have a look at it.
 
Upvote 0
Shouldn't happen like that if you have given proper references.

However, you can try changing this line :
x = Range("E2:E" & lr).Find(WHAT:="Z00", LookAt:=xlPart, SearchDirection:=xlPrevious).Row

To this line
x = Range("E2:E" & lr).Find(WHAT:="Z00", LookAt:=xlwhole, SearchDirection:=xlPrevious).Row

After making changes in the code if problem persists, just paste your entire code here so that the members can have a look at it.

here is the code. I have tried to point it at the word CONV which is also in column E. when i run the code it fills all of column O rather than only the lines with CONV in it.

Code:
Sub convformula()

Dim x As Long
Dim lr As Long
Worksheets("Layout").Activate
lr = Range("E" & rows.Count).End(xlUp).Row

    x = Range("E3:E" & lr).Find(WHAT:="CONV", LookAt:=xlWhole, SearchDirection:=xlPrevious).Row
   
    Range("o3:o" & x).Formula = "=K3*M3/N3"
   
End Sub

thanks heaps for your help so far
 
Upvote 0
here is the code. I have tried to point it at the word CONV which is also in column E. when i run the code it fills all of column O rather than only the lines with CONV in it.

Is CONV the entire cell value or is it a part of the cell like "Conventional" or "Conviction".
Also, until now I thought you have to put formula in the Entire column O. I will try to change my code.
 
Upvote 0
Is CONV the entire cell value or is it a part of the cell like "Conventional" or "Conviction".
Also, until now I thought you have to put formula in the Entire column O. I will try to change my code.
CONV is the text.

nope, only need the formula in the row that has the word CONV in it or Z004 etc etc.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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