tags:

views:

83

answers:

2

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?

+1  A: 
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?

shahkalpesh
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.
+2  A: 

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"