2017-07-13 2 views
1

Ich versuche, eine Formel für alle Spalten (Spalte B zum letzten Spalte mit Daten) eingefügt werden basierend auf dem Wert in Spalte AMakro einfügen Formel über mehrere Spalten

Unten ist das, was ich bisher:

Sub Insert_Falldown_Ratio_Formula() 
Dim Rng As Range 
Dim lRow As Long 
Dim lLastRow As Long 


lLastRow = Cells(Rows.Count, "A").End(xlUp).Row - 1 
lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column 

For lRow = lLastRow To 2 Step -1 

    If Cells(lRow, "A").Value = "Falldown Ratio" 
     Set Rng = Range("B" & (1Row) & ":" & lastcolumn) 
     Rng.FormulaR1C1 = "=IF(LEFT(RC[-1],2)=""45"",""45'"",IF(RIGHT(RC[-1],1)=""Q"",""40'HC"",LEFT(RC[-1],2)&""'""))" 

    End If 
Next lRow 
End Sub 

Jede Hilfe wird sehr geschätzt! Vielen Dank!

Antwort

0

Ein paar Dinge. (1) Sie haben einen Then auf Ihrer If Zeile (2) in der folgenden Zeile verloren. Sie hatten 1Row anstelle von lRow und (3) Sie kopierten eher als quer.

Sub Insert_Falldown_Ratio_Formula() 

Dim Rng As Range 
Dim lRow As Long 
Dim lLastRow As Long, lastcolumn As Long 

lLastRow = Cells(Rows.Count, "A").End(xlUp).Row - 1 
lastcolumn = Cells(1, Columns.Count).End(xlToLeft).Column 

For lRow = lLastRow To 2 Step -1 
    If Cells(lRow, "A").Value = "Falldown Ratio" Then 
     Set Rng = Range(Cells(lRow, "B"), Cells(lRow, lastcolumn)) 
     Rng.FormulaR1C1 = "=IF(LEFT(RC[-1],2)=""45"",""45'"",IF(RIGHT(RC[-1],1)=""Q"",""40'HC"",LEFT(RC[-1],2)&""'""))" 
    End If 
Next lRow 

End Sub 
+1

Vielen Dank für Ihre Hilfe! – Derek

Verwandte Themen