Renaming sheet using IF condition

Hi there, i am using studiox to rename a few sheets by reading a few cells. However, there are few duplicates found while renaming. How do i avoid the duplicate error using IF condition.

@Sudharsan_Ka

HI @Mark_Rajkumar

You can try like this
Click on the Filter in the Activity Panel → Enable Show Developer

  • Use Get WorkbookSheets and store in the variables Sheets_Available
  • in if Condition " Not Sheets_Available.Contains(“YourSheetName”)"
    True-> Rename sheet
    False-> Leave Empty

Regards
Sudharsan

I am reading 2 diff cells and storing the value. That will be sheet name. How do i put into tge syntax. True or false shld be placed where @Sudharsan_Ka

Hi

Complementing:
First you need to get the new sheets names in your variables

Then read the excel workbook sheets from the file that you want to rename the sheets, it will retrieve a list

in your if condition just ask if in that list exist the sheetname that you want

Not youSheetList.Contains(yourNewSheetNameStringVar)

in the then part rename the sheet, in the else part, leave it blank

Regards

@fernando_zuluaga the syntax not working for me

image

@fernando_zuluaga this is not working as well. I have 2 variable which is stored to rename. One A1 and the other is AA2. How to put them as syntax

@Mark_Rajkumar

Hope you have retrieved the sheets from excel using get worksheets and let the output be arr and let var1 and var2 are the two variables to be used then use condition as below

Arr.Any(function(x) x.Contains(var1) AndAlso x.Contains(var2))

This should be used in if condition and on the then side you have already existing sheets and on other side you have the remaining sheets

Cheers

Hi @Anil_G

My workflow is in a way that from a main sheet I have to create a new sheet and put in all the necessary activities. And than read 2 different cell to rename sheet. This steps repeat in a loop. However i happen to get stuck when the same values appear that throws error. I am trying to use IF condition to avoid the error.

@Mark_Rajkumar

Use get worksheets activity after you read cells.and before renaming or after reading the crlls use the if condition as stated above…so that if sheetname already exists we will know that

Cheers

The output for get worksheets have to be array? @Anil_G

@Mark_Rajkumar

Yes it would be a string array

Cheers

Hi @Anil_G it throws an error saying array of string cannot be converted. What is function(x) suppose to be in the syntax? Can i have an example for the syntax so will be easy to understand.

@Mark_Rajkumar

Please try this

Arr.AsEnumerable.Any(function(x) x.Contains(var1) AndAlso x.Contains(var2))

Function(x) is a lamda function which compares each seperate element of the array to contain var1 and var2

Cheers

Hi @Anil_G the array cannot read in get workbook sheets output if i use studio. However I am using studiox, so not sure why its not converting array to string.

@Mark_Rajkumar

Can you show what output you are getting theough get workbook sheets or get worksheets activity

Cheers

The worksheet variable is working now. The if condition not working.

@Anil_G fyi

@Mark_Rajkumar

arr is should be the output of your get worksheets activity

Error says there is no arr at all…

Create one and use in output and same in this condition

cheers