Frank was thinking very hard :
Hi Garry:
You can try the code I had posted earlier:
i = 1
For Each cell In Range("my_range")
i = i + 1
'insert new sheet
Worksheets.Add(After:=Sheet1).Name = "sheet" & i
Columns("C:C").Value = Columns("D
").Value
Next
While the code does not do anything, it just proves my piont that
there is a bug in Excel.
And here is another bug:
I'm developping an application where people can optimize data given a
slew of options.
Each execution requires that an existing sheet with data must be
duplicated in order performe calculations,
I discovered that using Sheets("test").Copy After:=Sheets("test") will
fail after running the execution after about 100 times (It depends how
much data is on Sheets("test").
It forces the user to close Excel. Once reopened, it works again until
the nex time.
So I have used the copy/paste method and it works fine.
Maybe they are solutions to those issues but I am not a programmer by
profession.
Hi Frank,
I still don't see where the contents of Columns("D") gets onto the
sheet so as to copy the value to Columns("C"), so I entered this
formula into several rows of Columns("D"):
=Row()*2
Then, in the Immediate Window I entered:
Columns("C").Value=Columns("D").Value
and the values appeared as expected.
I ran your code to add worksheets and populate the data as you are
doing. I got a memory error as did Helmut. (Probably because I had 8
apps running at the time, and so resources were heavily taxed) Just to
verify my hardware, I did this on a XP SP3 machine running 1.6ghz
processors (dual) with 2gb RAM. So nothing special there! I left all as
was to continue testing with the current tax on resources left in
place.
Next, I opened a new workbook with one sheet (my usual default #sheets)
and entered the following in the Immediate Window:
ActiveWorkbook.Sheets.Add After:=Sheets(1), Count:=40
and the 40 sheets appeared instantaneously.
Next, I grouped all the sheets from 2-41 and entered the following in
the Immediate Window:
UpdateSelectedSheets
which ran the following procedure:
Sub UpdateSelectedSheets()
Dim wks As Worksheet, vData() As Variant, c As Range
Dim lRows As Long, r As Long
With ActiveWorkbook.Sheets("Sheet1")
lRows = .UsedRange.Rows.Count
ReDim vData(lRows)
For r = LBound(vData) To UBound(vData)
vData(r) = .Cells(r + 1, "D").value
Next
End With
For Each wks In ActiveWindow.SelectedSheets
wks.Range("C1:C" & CStr(lRows)).value = vData
Next
End Sub
Just as instananeously as the 40 sheets were added, they were all
successfully updated with the data.
I repeated this by adding another 40 sheets, grouping all 80, and
running the UpdateSelectedSheets procedure again. I got the same result
without error!
Not sure this would work for you but I strongly recommend you consider
a different approach to adding AND updating the 40 sheets one at a
time. Setting object refs and maintaining variables adds to the
resources load, and so anything done in quantity should be done as much
as possible without over-taxing available resources.
If you google here in this NG you'll find code here to group sheets. If
not found then post back and I'll provide code.
In case we don't resolve this before M$ shuts this NG down, I'll try
finding this thread in the new location. (Assuming the posts are
archived there) Otherwise, we'll have to figure something out. I
already tried the NNTPbridge deal but when I signed in I was informed
that my credentials were already in use by another member. IOW, it
didn't recognize me as me! Kinda put me off wanting to persist further.
regards,