Excel Shapes?

Kariya

New Member
Joined
Apr 29, 2015
Messages
21
Hi all,

I have the following VBA code which assigns the variable "Data" with the value of the Shape called "Box" on my sheet. It's generated by the Macro Recorder. However, when running it, it selects the box. How do I re-write it to exclude the "Select" suffix?

Code:
   Worksheets("Sheet1").Activate
    ActiveSheet.Shapes.Range(Array("Box")).Select
    Data = Selection.ShapeRange(1).TextFrame2.TextRange.Characters

Thanks for the help!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The general rule of thumb is that when you see Select followed by Selection you can eliminate both statements and pull together the remainder. Shapes and charts are often the exception though, as they don't always like not being selected first.
 
Upvote 0
The general rule of thumb is that when you see Select followed by Selection you can eliminate both statements and pull together the remainder. Shapes and charts are often the exception though, as they don't always like not being selected first.

I see :biggrin: Thank you for the tip. I tried different variations - but to no avail, was close enough though. I'm forcing myself to learn VBA by doing something that I have an interest in. In this case, reading CSV/TXT soccer/football historical data from here and aggregating the results with the options of viewing each round of the league & selecting the range of games for the "recent form". It's working as I'm finally learning :eek:

QJ25udW.png
 
Upvote 0
I tried different variations - but to no avail, was close enough though. I'm forcing myself to learn VBA by doing something that I have an interest in.

Looks like you're doing a great job!

When I'm teaching Excel classes and we get to VBA I always tells people that the Macro Recorder is your friend, but while you're learning, you should definitely record processes with which you're intimately familiar. That way the code makes sense to you when you try to read it.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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
Back
Top