Avatar of Shanan212
Shanan212
Flag for Canada

asked on 

Object doesn't support this property or method Error

    Dim BaseWks As Worksheet, lastrow As Long, n As Integer
    
    Dim wkb As Workbook, rngTarget As Excel.Range

     Set wkb = ThisWorkbook
 
    Set BaseWks = ActiveSheet
    lastrow = BaseWks.UsedRange.Rows.Count - BaseWks.UsedRange.Row + 1
      
    Set rngTarget = Range(BaseWks.Cells(1), BaseWks.Cells(lastrow, 1))
    rngTarget.FormulaR1C1 = "= VLookup(RC[1], 'GL Summary'!Ranges, 2, False)"
    
    Set rngTarget = Range(BaseWks.Cells(1), BaseWks.Cells(lastrow, 1))
    rngTarget.FormulaR1C2 = "= VLookup(RC[2], 'GL Summary'!Ranges, 3, False)"
    
    Range("A1:E1") = Split("Branch, Category, GL ID,Sum of Debt,Sum of Credit", ",")

    BaseWks.Columns.AutoFit

Open in new window


Morning,

I am trying to run the above coding within a function. First column contains the first formula, and second column contains the formula below.

I am getting an error 'Object doesn't support this property or method' on this line

rngTarget.FormulaR1C2 = "= VLookup(RC[2], 'GL Summary'!Ranges, 3, False)"

Sample of data I have is below:

First formula is being used to find out range and 2nd is being used to find out Category column! Vloopup is looking at GL ID as reference.


Branch      Category  GL ID                     Sum of Debt      Sum of Credit      
#N/A            2130-01HST      413.47      0
#N/A            2155-01UNION      0      31704.54
#N/A            2168-01CPP PAY      0      153382.12

I tried all possible combinations but the error wouldn't go away from that line! Any help is much appreciated!

Thanks!
Microsoft Excel

Avatar of undefined
Last Comment
Shanan212

8/22/2022 - Mon