Cell value in Code; not working

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
719
Hello friends, hope all is well!

Please help me fix the below code; this line has an error:
Sheet2.Shapes("& Sheets("Report").Range("D4").Value&"")" & .Visible = True

Thank you very much in advance

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("D4")) Is Nothing Then

Select Case Sheets("Report").Range("D4").Value

Case Sheets("Report").Range("D4").Value
Sheet2.Shapes("& Sheets("Report").Range("D4").Value&"")" & .Visible = True

End Select

End If
End Sub
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,068
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
That line should look like this:

Code:
Sheet2.Shapes(CStr(Sheets("Report").Range("D4").Value)).Visible = True
 

countryfan_nt

Well-known Member
Joined
May 19, 2004
Messages
719
great, thank you! a new problem if you don't mind. I am getting the error: Run Time Error: The item with the specified name wasn't found.
please help me correct the code above. btw the code is supposed to look like this: Sheet2.Shapes("7").Visible = True, but instead of fixing it to 7, I chose to allow it to have more flexibility.
and yes there is a shape called 7.

thanks again!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,068
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Either the shape name is wrong, or the value in D4 is not actually 7 - perhaps it has leading or trailing spaces?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,597
Messages
5,597,085
Members
414,121
Latest member
DamianX88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top