Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't use ActiveSheet in a formula

I tried to insert my ActiveSheet name inside a formula. Still doesn’t understand why it didn’t worked…

Sub AddResume()

    Dim ws As Worksheet: Set ws = Worksheets("Résumé")
    Dim LastRow As Long: LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
    Dim namee As String: namee = ActiveSheet.Name
    
     ActiveSheet.Range("B1").Copy
     ws.Cells(LastRow, 1).PasteSpecial xlPasteValues

Application.CutCopyMode = False
 
    For i = 1 To 200
       If ws.Cells(i, 1) = ActiveSheet.Range("P3").Value Then
          ws.Cells(i, 2).FormulaR1C1 = "=""&namee&"!P3"
       End If
    Next
  
Application.CutCopyMode = False
 

End Sub

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have to put the sheets variable name into single quotes

ws.cells(i,2).Formula = "='" & namee & "'!P3"

And as you are referencing a cell – you don’t need FormulaR1C1 which is for a relative formula.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading