Hello all. I am looping and creating new sheets. I am using the CreateRange in a loop saying for example
sheet1 = workbook.Worksheets.Add(dr(“InvestmentName”).ToString())
sheet1.Cells.CreateRange(“D” & rowCount + 69, “D” & (rowCount * 3) + 179).Name = "rngSDO_PS"
when the workbook opens the range is on the last sheet only when it should be on all of them. If I look in Named Manager I only see the last sheet all the ranges listed. Any idea
Hi,
It looks you are assigning the same name i.e.., "rngSDO_PS" for all the named ranges you create in all the worksheets in the workbook. When you create multiple ranges with the same name, the last range will be overwritten over all.
I tried the following code and it works fine, kindly consult it and try to change the names for each named range, the name should be unique.
Sample code:
[VB]
Dim workbook As New Workbook()
workbook.Worksheets.Clear()
Dim sheet1 As Worksheet
For i As Integer = 0 To 4
sheet1 = workbook.Worksheets.Add("Sheet" & i)
sheet1.Cells.CreateRange("D2", "F5").Name = "rngSDO_PS" & i
Next i
workbook.Save("f:\test\mybookrngs.xls")
[C#]
Workbook workbook = new Workbook();
workbook.Worksheets.Clear();
Worksheet sheet1;
for(int i = 0;i<5;i++)
{
sheet1 = workbook.Worksheets.Add("Sheet" + i );
sheet1.Cells.CreateRange("D2", "F5").Name = "rngSDO_PS" + i;
}
workbook.Save("f:\\test\\mybookrngs.xls");
Thank you.
Hi,
And please try the attached version (latest fix).
Thank you.
The issues you have found earlier (filed as 6763) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Laurence.