473,396 Members | 2,092 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,396 software developers and data experts.

How to create a Macro that runs on a selection of cells

OK, So I have a very specific problem that I hope to make not-a-problem, but I need some help. I am a complete neophyte when it comes to making Macros.

I’ve got a customer that has put long lists of references in a single column in Excel (normally, the references are just in one cell). I’ve figured out how to consolidate a selected portion of a column of references into a single cell (see my procedure below), but what I’d really like to do is to turn this into a Macro that does it instantly.

The problem is that I’d like to be able to run a Macro on a selection, that is, I’d like to select the cells and have the macro run on ONLY those cells. Then I could select the cells, run the macro, make another selection, run the macro, etc. This would speed up my work tremendously.

My problem: I can’t figure out how to make the Macro run on just a selection. The Macros I’ve recorded only run on the selections I’ve made while recording the Macro. Is there any way to make the Macro generic, so I can select cells, and then run the Macro on them?


Combining References in Excel

1. Let’s say the references you want to combine are in E18:E27
2. Make a new column next to the reference designator column, for consolidated references
3. In a blank cell in the new column, where you want to combine all the values, type:
4. =CONCATENATE(TRANSPOSE(
5. Then select the cells that need to be combined
6. The formula will change to =CONCATENATE(TRANSPOSE(E18:E27
7. Don’t press enter yet.
8. Click after the last cell reference and hit spacebar
9. Type the & operator
10. Type ”, ” (double quote, comma, space, double quote)
11. This will add a comma and a space after every reference
12. Select TRANSPOSE(E18:E27 &", " and press the F9 key (F9 replaces formulas with values)
13. This replaces TRANSPOSE(E18:E27 &" " with its result, {"E18, ","E19, ","E20, ","E21, ","E22, ","E23, ","E24, ","E25, ","E26, ","E27, "}
14. Now remove the curly brackets { and }
15. The formula will now look like =CONCATENATE("E18, ","E19, ","E20, ","E21, ","E22, ","E23, ","E24, ","E25, ","E26, ","E27, "
16. Select the entire formula, including the = sign, and hit F9
17. Hit Enter
18. Done!



Note: this only works for up to 256 references. Any more and the formula will thrown an error. If there's any way to change it so it will work on more than that, please let me know.
Nov 12 '18 #1
2 5122
Rabbit
12,516 Expert Mod 8TB
This question has been moved to the Excel forum.
Nov 13 '18 #2
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Sub Macro1()
  2.     If Selection.Cells.Count > 256 Then
  3.         MsgBox ("Too much cells selected ...")
  4.     Else
  5.         'Do your stuff here....
  6.     End If
  7. End Sub
  8.  
You should let the user select the cells, and than run the macro.
It will notify the user if more than 256 cells are selected.
Nov 17 '18 #3

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

Similar topics

2
by: geronimo_me | last post by:
Hi, I have the following code in an access module: Sub Run_Excel_Macro() Dim xls, xlWB As Object Dim strFile, strMacro As String
1
by: ghadley_00 | last post by:
Hi, I have a MS access database table for which I regularly need to import fixed width text data. At present I have to to cut and paste the text data from its source to a text file, save the...
0
by: derelict | last post by:
Hey all, im getting desperate now. I have a macro running in Word 2003, when I run the macro it *should* put a 'bottom' cell border in each cell that has the style used - this included a border at...
3
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
2
by: jl2886 | last post by:
Is there a way to create a macro that, based on certain criteria(disposition status and date received), removes a line from one table and adds it to another.
1
by: Emmanouil | last post by:
Goodmorning to every body!!!!! My "problem" for 2day is this: I have a column in a access database with 50 cells, let us say. All cells are filled with 1 and 0 quite like these: 1 0 0 1 1 0
5
daoxx
by: daoxx | last post by:
Hi I didn't find anything with the search - the words are too general. How can I create a macro and define what it does from code? EDIT: The other question was To do this use...
2
by: Stratocaster | last post by:
Hello, and thank you for any help in advance. I need help determining if any commands exist in VB (Excel macro style) that can enable a user to select cells and run a macro which performs...
4
by: jimatqsi | last post by:
I am working in Access 2003. I have written some code to add a context menu to a Treeview. I have a working right-click menu, I right-click on a node, I get my options and I choose "Display Details"...
8
USTRAGNU1
by: USTRAGNU1 | last post by:
Good Day, I created a macro in Excel that works great. It formats multiple sheets exactly as expected, but when it completes it seems like I have to close out four or five worksheets before I can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.