2016-04-07 12 views
0

Aşağıdaki kodum var ancak makroyu çalıştırmayı denediğimde bir hata alıyorum.
Makrolarıma dayanarak, ölçütlere bağlı olarak hareketli bir sütun var. Bu yüzden sütun numarasını almak için kod ekledim. ColRef1'a bakın.
Yapmakta olduğum sorun, bunu IF ve formülüme eklemeye çalıştığım zamandır. Sorun, formülün ilk parçası ve belki de yanlış yazıyor.VBA IF ve Formül referanslı RC Aralığı

Sub Test() 
    Dim GetRow1 As Integer 
    Dim GetRow2 As Integer 
    Dim GetRow3 As Integer 
    Dim GetCol1 As Range 
    Dim GetCol2 As Range 
    Dim ColRef1 As Integer 

    'finds last row on Client Options tab 
    Sheets("Client Options").Select 
    GetRow1 = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row 

    'finds last row on Client Response tab 
    Sheets("Client Response").Select 
    GetRow2 = ActiveSheet.Cells(Rows.Count, "E").End(xlUp).Row 

    'finds last row on Recon tab 
    Sheets("Recon").Select 
    GetRow3 = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row 

    'finds Column that contains Client Options since this is a moving column depending on number of brokers on recon 
    Sheets("Recon").Select 
    Set GetCol1 = ActiveSheet.UsedRange.Find("Client Options", , xlValues, xlWhole) 
    ColRef1 = GetCol1.Column 

    Sheets("Recon").Select 
    Range("B2").Value = "=IF(AND(RC&ColRef1&>0,U2>0),""FALSE"",IF(T2>0,(VLOOKUP(A2,'Client Options'!G$2:L$" & GetRow1 & ",6,FALSE)),IF(U2>0,(VLOOKUP(A2,'Client Response'!E$2:G$" & GetRow2 & ",3,FALSE)))))" 


End Sub 

cevap

1
  • Sen formülde A1 stilleri ile R1C1 stillerini birleştiren ediyoruz IF(AND(RC&ColRef1&>0,U2>0).
  • ColRef1 dizenin içinde olduğundan, RC5 (örneğin) yerine RC&ColRef1 referans vermeye çalışıyor.
  • Yan not - bununla çalışmak için sayfayı seçmeniz gerekmez.

Bu kodu deneyin (not - U2 adresi R2C21 olmalıdır).

Sub Test() 

    Dim GetRow1 As Long 
    Dim GetRow2 As Long 
    Dim GetRow3 As Long 
    Dim GetCol1 As Range 
    Dim ColRef1 As Long 

    'finds last row on Client Options tab 
    GetRow1 = Sheets("Client Options").Cells(Rows.Count, "G").End(xlUp).Row 

    'finds last row on Client Response tab 
    GetRow2 = Sheets("Client Response").Cells(Rows.Count, "E").End(xlUp).Row 

    'finds last row on Recon tab 
    GetRow3 = Sheets("Recon").Cells(Rows.Count, "A").End(xlUp).Row 

    'finds Column that contains Client Options since this is a moving column depending on number of brokers on recon 
    Set GetCol1 = Sheets("Recon").UsedRange.Find("Client Options", , xlValues, xlWhole) 
    If Not GetCol1 Is Nothing Then 
     ColRef1 = GetCol1.Column 

     Sheets("Recon").Range("B2").FormulaR1C1 = "=IF(AND(RC" & ColRef1 & " >0,R2C21>0),FALSE,IF(R2C20>0,(VLOOKUP(R2C1,'Client Options'!R2C7:R" & GetRow1 & "C12,6,FALSE)),IF(R2C21>0,(VLOOKUP(R2C1,'Client Response'!R2C5:R" & GetRow2 & "C7,3,FALSE)))))" 
    End If 

End Sub 
+0

Günümü siz yaptınız. Bu bir çekicilik çalışır. Yardımlarınız ve tavsiyeleriniz için teşekkürler. Çok takdir !!! – Conor