I want to combine text of 1000 cells of a particular column (say from A1 to A1000) to one single cell (say A1001), can anybody tell the macro for this?
Asked
Active
Viewed 2,003 times
2 Answers
0
Try the following UDF
Public Function concat(r As Range) As String
concat = ""
For Each rr In r
concat = concat & rr.Value
Next rr
End Function
User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I ALT-M opens a fresh module
- paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=concat(A1:A1000)
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and
http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx
for specifics on UDFs
Macros must be enabled for this to work!

Community
- 1
- 1

Gary's Student
- 95,722
- 10
- 59
- 99
-
I pasted this on visual basic page and saved but no working as I tried to concatenate 2 selected cells where failed. Can you elaborate more or tell with example – Sidharth Jun 22 '14 at 13:38
-
-
=concat(A1:A1000) this formula is not working despite I have saved UDF in VBE window – Sidharth Jun 22 '14 at 14:31
-
-
Formula desplayed is same as excel have i.e. =concatenate(.... not one which I have entered. – Sidharth Jun 23 '14 at 07:07
-1
=concatenate(A1:A1000)
As the formula in A1001

Steve Barnes
- 27,618
- 6
- 63
- 73
-
Sorry I haven't go excel on this machine to check it out - are all the values text values? – Steve Barnes Jun 22 '14 at 14:10
-
Sadly, `CONCATENATE` doesn't take accept a range. Rather it accepts it but only concatenates the first cell in the range. – Doug Glancy Jun 22 '14 at 16:32