0

I'm trying to copy an existing sheet in my workbook and then I want to use the copied sheet to run the rest of my code. (Sheet3 is the existing sheet, S_Temp is the copied sheet)

Dim s_Temp as string
Sheet3.copy 
Activesheet.name = S_Temp
Sheets("S_Temp").Range("A1").value = "Test"

How can I reference to the copied sheet?

2 Answers 2

2

Here's the solution I've just found:

Dim s_Temp as Worksheet
Sheet3.copy   
set S_Temp  = Activesheet  
S_Temp.Range("A1").value = "Test" 
Sign up to request clarification or add additional context in comments.

Comments

1
Sheet3.copy 
'From this point onwards, the active sheet has changed
Activesheet.name = S_Temp

'Hence, this will be A1 on the copied sheet.
Range("A1").value = "Test"

Have I misunderstood the question?

2 Comments

Thanks shahkalpesh, I've found my mistake, see my answer
That's partially what I wanted to do. The problem was when you first copy sheet3 it becomes by default your activesheet. Then I select another sheet's data to paste in my copied sheet3. I didn't how to reference the copied sheet since its name is created by excel randomly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.