Hello all,
I am new to the world of VBA and just started working on creating macros about 5 weeks ago. I have been watching YouTube videos and reading blogs to help me get going.
I have the code below that stops working when new sheets are created from the template. I realized after the fact and googling my issue that I should have used the sheet CodeName to write the code so that if the name of the sheets changed the code would still work. However, I tried changing it to reflect the CodeName Sheet1 (corresponds to Evaluations) and Sheet2 (corresponds to Template), and when I run the macro I keep getting error codes. How can I incorporate the sheet codename so that even if the sheet names change the code will still function?<!--[if gte mso 9]>
I am new to the world of VBA and just started working on creating macros about 5 weeks ago. I have been watching YouTube videos and reading blogs to help me get going.
I have the code below that stops working when new sheets are created from the template. I realized after the fact and googling my issue that I should have used the sheet CodeName to write the code so that if the name of the sheets changed the code would still work. However, I tried changing it to reflect the CodeName Sheet1 (corresponds to Evaluations) and Sheet2 (corresponds to Template), and when I run the macro I keep getting error codes. How can I incorporate the sheet codename so that even if the sheet names change the code will still function?<!--[if gte mso 9]>
Code:
Option Explicit
Sub Comments()
Application.ScreenUpdating = True
Dim Template:confused: As Worksheet
Dim Evaluations:confused: As Worksheet
Dim Nb_Rows As Integer
Dim i As Integer
Dim x, Row As Integer
Set Template = ThisWorkbook.Sheets("Evaluation Form Template")
Set Evaluations = ThisWorkbook.Sheets("Evaluations")
Template.Range("A61:A70").ClearContents
' the table in this example starts in A1
Nb_Rows = Evaluations.[a1].CurrentRegion.Rows.Count
Row = 61 ' first row to input results in Template
x = 0 ' needed to increment
For i = 1 To Nb_Rows
If Evaluations.Cells(i, 1) = Template.[a1] Then
Template.Cells(Row + x, 1) = Evaluations.Cells(i, 29)
x = x + 1
End If
Next i
Set Template = Nothing
Set Evaluations = Nothing
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: