Please help me optimize this code..
Public Sub createNextMonthSheets(ByRef io As InputOutput)
Dim WB As Excel.Workbook = getWorkBook(io.newClientReportHandle)
For Each name In clientSheetNames.FindAll(AddressOf findCurrMonthSheetNames)
For Each sheet In WB.Sheets
If (sheet.Name = name) Then
sheet.Name = name.Replace(currMonth, nextMonth)
sheet.Copy(After:=WB.Sheets(1))
End If
Next sheet
Next name
WB.Close()
End Sub
Private Function findCurrMonthSheetNames(ByVal sheetName As String) As Boolean
If sheetName.Contains(" (" + currMonth + ")") Then
Return True
Else
Return False
End If
End Function
I am new to vb.net and don’t know the power of this language.
See if you can optimize this on performance !!
See if you can optimize this on fewer lines of code that does the same thing.
You can introduce new aspects of the language that can make this more readable !
Can you overload the findcurrmonthsheetnames function in some way to get the WB.sheets ?
In response to your nested loops question, you can extract all of the required names into a separate array first, then scan the array for each existing name.