I have different random strings (eg. “MI123”), i am supposed to create excel sheets with names like “MI123” but if it exists, i am supposed to create “MI123 (1)” and if it exists, create “MI123 (2)”… and so on.
How am i supposed to find out what is the number inside the () so that i can +1 for the next sheet to be created?
Disclaimer: Not only do i have “MI123”, i have to create “MI123 X1” and “M123 X2”. Same for both X1 and X2, I will have to increment the numbers if (e.g. “M123 (1) X1”) exists, i will have to create “M123 (2) X1”.
Can anybody please help me out? I was thinking of checking number of occurrence so that i can +1 to the number of occurrence. However, I got confused halfway through.
Here is the VBA code to check whether the sheet exists or not,
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Worksheets
If Application.Proper(Sht.Name) = Application.Proper(WorksheetName) Then
WorksheetExists = True
Exit Function
End If
Next Sht
WorksheetExists = False
End Function
and to change the sheet name, you can declare a new variable, let say Count.
Change the sheetname as,
Then call the same function, to check whether the name exists or not and repeat the same if exits Note : Change WorksheetExists to False after the loop exists
Hello! Thank you for replying, i might not fully understand the VBA codes as i am a beginner to UiPath, i do not understand the Application.Proper part, do you mind explaining a little bit more?
I have imported the package but still there were errors. Sorry, but is it possible for me to visually see the workflow example? I might not catch everything that you have said especially with the Exit function and End function part.