Find, and replace with offset a cell

TitoElan

New Member
Joined
Jun 10, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi there. I did one macro to find a value, then change a cell's value with an offset. Just a string. It is working. Now I just wanted to use the same macro, but I dont want to replace the content from the offset matching cells with a string but with a formula. And I have tried for hours to find a solution without success. Maybe I can get some help here. I would appreciate it. The code (last try) looks like this
That code finds well the cells, but without a relative formula and I need It.
If I try to use myFormula = "=IF(RC[-9]>0,IF(RC[-8]=1,VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,3,FALSE),VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,2,FALSE)),"""")" as formula nothing happends. Kinda sad. It is like almost done but I cant get it working.

VBA Code:
Sub Schaltfläche4_Klicken()
Dim find_value, replace_value As String
Dim i As Long
Dim myFormula As String
Dim Rng As Range
Dim Rng_2 As Range
Dim c As Range

On Error Resume Next

myFormula = "=IF(RC[-9]>0,IF(RC[-8]=1,VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,3,FALSE),VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,2,FALSE)),"""")"
find_value = InputBox("Wählen Sie den Profiltyp zB. QRR oder ROHR...")

 

i = 0
For Each Rng In Worksheets("Tabelle1").Range("E6:E28")
 
    If Rng.Value Like "*" & find_value & "*" Then
        Rng.Offset(0, 9).Formula = "=WENN(E17>0;WENN(F17=1;SVERWEIS(E17;matpreis!$A$1:$G$2567;3;FALSCH);SVERWEIS(E17;matpreis!$A$1:$G$2567;2;FALSCH));"""")": i = i + 1
        
    End If


        '=WENN(E17>0;WENN(F17=1;SVERWEIS(E17;matpreis!$A$1:$G$2567;3;FALSCH);SVERWEIS(E17;matpreis!$A$1:$G$2567;2;FALSCH));"""")
        '=IF(RC[-9]>0,IF(RC[-8]=1,VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,3,FALSE),VLOOKUP(RC[-9],matpreis!R1C1:R2567C7,2,FALSE)),"""")
    

Next

If i = 1 Then
MsgBox i & " Zelle geändert"
ElseIf i > 1 Then
MsgBox i & " Zellen geändert"
Else
MsgBox "Keine Zellen geändert"
End If



End Sub
 
Just change the range references from A1 notation to R1C1 notation as you've done for the English version of the formula.
OOMMG
I get the formula with
VBA Code:
Sub RunThis()
    MsgBox ActiveCell.FormulaR1C1
End Sub

and now it works. Thanks Fluff, it was already a bad day because of vba.
 
Upvote 0

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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