# Variable not defined in current scope

**URL:** <https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118>\
**Category:** StudioX\
**Tags:** question, excel, uiautomation, activities\
**Created:** [June 28, 2022, 7:06pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118 "2022-06-28T19:06:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Dowd](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alex_dowd/32/254207_2.png) [@Alex\_Dowd](https://forum.uipath.com/u/Alex_Dowd)\
**Post date:** [June 28, 2022, 7:06pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/1 "2022-06-28T19:06:24Z")

</div>

I am using a variable inside of a For Each Excel Row activity in the aaname field of the strict selector (aaname = ‘myvariable’). The purpose of this is to allow for accurate and dynamic targets/anchors when searching IDs that return multiple results, of which the ID searched for is one. UiPath is saying the variable is “not defined in the current scope” even though I defined in the For Each Excel Row activity and the click activity using the variable is inside the same Excel activity. Any ideas or something I’m missing maybe?

---

<div class="post-metadata">

**Author:** ![muhammedyuzuak](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/muhammedyuzuak/32/370135_2.png) [@muhammedyuzuak](https://forum.uipath.com/u/muhammedyuzuak)\
**Post date:** [June 28, 2022, 7:32pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/2 "2022-06-28T19:32:22Z")

</div>

Hi @Alex_Dowd,

Can you share a screenshot.

Regards,  
MY

---

<div class="post-metadata">

**Author:** ![Alex\_Dowd](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alex_dowd/32/254207_2.png) [@Alex\_Dowd](https://forum.uipath.com/u/Alex_Dowd)\
**Post date:** [June 28, 2022, 7:41pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/3 "2022-06-28T19:41:59Z")

</div>

![1](https://global.discourse-cdn.com/uipath/original/4X/2/a/9/2a9f080440ea2ee1745849a12e0fbcac354a31a0.png)

I should note that this is only happening with the Target strict selector; the anchor strict select works fine with a different variable, but neither variable works here.

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 28, 2022, 7:42pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/4 "2022-06-28T19:42:52Z")

</div>

please check if an appropriiate default value is set for the variable

> [@Can I add variable as well as wildcard character in selector](https://forum.uipath.com/t/can-i-add-variable-as-well-as-wildcard-character-in-selector/446961/13):
>
> When opening your XAML we saw this: And clicked on the number variable block from selector; [grafik] we clicked on cancel entered “13” as default value on the variable number on variable panel checked again on the selector and issue was gone [grafik] Maybe the error message is wrong or misleading. But can check similar at your end?

---

<div class="post-metadata">

**Author:** ![Viswanathan\_A\_M](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/viswanathan_a_m/32/266766_2.png) [@Viswanathan\_A\_M](https://forum.uipath.com/u/Viswanathan_A_M)\
**Post date:** [June 28, 2022, 7:49pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/5 "2022-06-28T19:49:39Z")

</div>

> [@Alex\_Dowd](#):
>
> defined in the For Each Excel Row activity and the click acti

Check list:  
\*Remove the unused variable and make sure you are having the proper variable  
\*Open the UIExplorer and right click on your aaname variable and select the variable as per the below  
\*And keep log message , That will help you to debug it.

if you still face any issue, Please share the issue screenshot 🙂

![image](https://global.discourse-cdn.com/uipath/original/4X/0/1/c/01c214a39505c7263004a5b2202628b4dbc580e7.png)

---

<div class="post-metadata">

**Author:** ![Alex\_Dowd](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alex_dowd/32/254207_2.png) [@Alex\_Dowd](https://forum.uipath.com/u/Alex_Dowd)\
**Post date:** [June 28, 2022, 8:39pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/6 "2022-06-28T20:39:05Z")

</div>

This didn’t solve the original issue which is the variable being declared out of scope. UiPath is unable to correctly find the target, presumably because of this, even though i am separately verifying that the variable contains the correct field via message box

---

<div class="post-metadata">

**Author:** ![Alex\_Dowd](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/alex_dowd/32/254207_2.png) [@Alex\_Dowd](https://forum.uipath.com/u/Alex_Dowd)\
**Post date:** [June 28, 2022, 8:39pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/7 "2022-06-28T20:39:20Z")

</div>

This didn’t change anything i’m afraid

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [June 28, 2022, 8:40pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/8 "2022-06-28T20:40:10Z")

</div>

better you show us the details as similar in the linked post. So we can better help

---

<div class="post-metadata">

**Author:** ![Viswanathan\_A\_M](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/viswanathan_a_m/32/266766_2.png) [@Viswanathan\_A\_M](https://forum.uipath.com/u/Viswanathan_A_M)\
**Post date:** [June 28, 2022, 8:41pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/9 "2022-06-28T20:41:31Z")

</div>

Could you please provide your error screenshot here 🙂

---

<div class="post-metadata">

**Author:** ![anamika1506](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/anamika1506/32/263153_2.png) [@anamika1506](https://forum.uipath.com/u/anamika1506)\
**Post date:** [December 1, 2022, 7:50am UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/10 "2022-12-01T07:50:55Z")

</div>

Did you get solution for this issue? Facing the same.

---

<div class="post-metadata">

**Author:** ![Josh\_James](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/josh_james/32/283612_2.png) [@Josh\_James](https://forum.uipath.com/u/Josh_James)\
**Post date:** [May 22, 2023, 2:19pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/11 "2023-05-22T14:19:31Z")

</div>

I am also having this issue.

---

<div class="post-metadata">

**Author:** ![Subha\_Sriram](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/subha_sriram/32/375856_2.png) [@Subha\_Sriram](https://forum.uipath.com/u/Subha_Sriram)\
**Post date:** [July 10, 2023, 2:42pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/12 "2023-07-10T14:42:13Z")

</div>

Even i am also facing same issue even though declared variable in the main scope. Can you please help me on this

---

<div class="post-metadata">

**Author:** ![Subha\_Sriram](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/subha_sriram/32/375856_2.png) [@Subha\_Sriram](https://forum.uipath.com/u/Subha_Sriram)\
**Post date:** [July 24, 2023, 5:11pm UTC](https://forum.uipath.com/t/variable-not-defined-in-current-scope/452118/13 "2023-07-24T17:11:55Z")

</div>

Can you please help me on this how to fix this issue
