473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using a counter within a name in VBA

I am trying to automate a simple function that resets shapes to a specified location.

For instance, let's say there are 4 blue squares on your worksheet, titled Blue1-Blue4.

The following lines of code accomplish what I wish to do:


Expand|Select|Wrap|Line Numbers
  1. ActiveSheet.Shapes("blue4").Left = 20
  2. ActiveSheet.Shapes("blue4").Top = 40


But this requires 4 repititions of those two lines of code. I am looking for a loop that will allow me to make this happen to all the squares at once, as I have a lot more than 4 blue squares. Something along the lines of:


Expand|Select|Wrap|Line Numbers
  1. For i = 1 To 4
  2. ActiveSheet.Shapes("Blue" & i).Left = 20
  3. ActiveSheet.Shapes("Blue" & i).Top = 40
  4.  
  5. Next i
Additional information:
Yes I want the shapes to all go to the same place.

Thanks in advance to anyone who can help.

-Rob
Sep 2 '13 #1

✓ answered by Rabbit

Please use code tags when posting code.

Your thread has been moved to the Excel forum.

You can do exactly what you have in your post.

3 1776
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

Your thread has been moved to the Excel forum.

You can do exactly what you have in your post.
Sep 2 '13 #2
Thank you for editing and moving my post as appreciated. I posted my question before I joined, so I didn't realize I hadn't followed all the requirements. For that, apologies.

In response to your answer, I thought I had tried exactly that. I went back and tried it again, and it worked. I'm not really sure what I did differently before that did not work.

Thank you so much for your reply, I greatly appreciate it.
Sep 3 '13 #3
Rabbit
12,516 Expert Mod 8TB
No problem, it was most likely just a typo last time it didn't work, happens to everyone.
Sep 3 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Fred | last post by:
Hi all, I have done a lot of experimentations using several "or" predicates within an sql select statements on mysql. My only conclusion so far is that whatever syntax or order I use it is...
3
by: Phil Myers | last post by:
I have a C# namespace called SAP_Message_Processor with a class called App with a method called RunstateCreate. I want to refer to the RunstateCreate method from another class called...
5
by: sianan | last post by:
I have an ASP.NET custom control, which contains a DataGrid with checkboxes. I am trying to figure out how to retrieve the selected records, based on the checkbox's checked state. I want to send...
1
by: Tor Inge Rislaa | last post by:
Using PowerPoint within my application I am developing an application that needs some functionality of displaying some text and graphic in full screen modus, as when you run a PowerPoint show....
8
by: Sameh Ahmed | last post by:
Hello there I need to get a list of domain controllers to a domain I bind too using it's name rather than the DN. I am trying a query looking for objectClass=nTDSDSA but this returns 0 results I...
5
by: Tristán White | last post by:
As some of you who helped with my "No input file selected" query earlier already know, I've just started a new job and am new to PHP. All the webpages are PHP, but contain HTML as a string...
6
by: Bora Ji | last post by:
Please help me to creating dynamic VARIABLE in java, with predefined name.
10
by: Evan Charlton | last post by:
Hey all, I'm having some trouble with window.setInterval() within a custom object/prototype. Here is my code: function MyClass() { // do some junk // ... // define methods this.m_one =...
3
by: duyanning | last post by:
I have written a pyhton script that will process data file in current working directory. My script is in an different directory to data file. When I debug this script using pdb within emacs, emacs...
3
by: Ilyas | last post by:
Hi all What is the recommended way for using Linq within a 3 Tier project? Many thanks
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.