![]() |
activate current sheet
Hi,
In VBA I have a for loop that adds multiple sheets. At the end I want to add a final sheet that is situated in the beginning. I tried this VBA code but when I looked at the file, a new sheet was created but was not populated with data. I know that you have to activate the sheet somehow, but I must be losing memory as I forgot how to. Any help is appreciated. This is what I have now. Worksheets.Add befo=Sheets(1) Sheets(1).Select Range("A1").Value = "Sector" Range("A2").Value = "3/31/2006" ...... |
activate current sheet
Hi
Works for me. The Select activates the sheet (as does the Add), so your code might be creating some other problem before this. Do you really put in the word "Sector" and the hard coded date, or do you get it from somewhere else, and are just simplifying the question? regards Paul |
activate current sheet
Is your code in a general module or behind a worksheet?
If it's behind a worksheet, you can fully qualify your range and it'll work. sheets(1).range("a1").value = "Sector" sheets(1).range("a2").value = dateserial(2006,3,31) An unqualified object (like a range) belongs to the activesheet if the code is in a general module. But if the code is behind a worksheet, then those unqualified ranges belong to the sheet owning the code. Make sure you check A1 and A2 of that sheet to see if you changed anything important. ask72883 wrote: Hi, In VBA I have a for loop that adds multiple sheets. At the end I want to add a final sheet that is situated in the beginning. I tried this VBA code but when I looked at the file, a new sheet was created but was not populated with data. I know that you have to activate the sheet somehow, but I must be losing memory as I forgot how to. Any help is appreciated. This is what I have now. Worksheets.Add befo=Sheets(1) Sheets(1).Select Range("A1").Value = "Sector" Range("A2").Value = "3/31/2006" ..... -- Dave Peterson |
All times are GMT +1. The time now is 03:34 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com