Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Hi! I have no experience with programming macros so bear with me. I'm not
sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Hi
This will put your string on sheet "mydata" in cell "A1". The selected cells can be anywhere on the active sheet, and you would need further error checking if you want to restrict people to one particular column. Names will be seperated by commas, but you can change this below. you will get an error if no cells are selected. Sub tester3() Dim Cell As Range Dim mystring As String For Each Cell In SelectedRange mystring = mystring & ", " & Cell.Text Next Cell 'take off leading 2 characters ", " mystring = Right(mystring, Len(mystring) - 2) Worksheets("mydata").Range("a1").Value = mystring End Sub regards Paul On May 11, 9:24 am, OTS wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Hi ! I have made a litlle programm fpr your problem.
Create a button and write code like you see here in the modul: Sub Button1_Click() Dim oData As New DataObject Dim sText As String For Each cell In Selection.Cells On Error Resume Next 'ignore all errors sText = sText & CStr(cell.Value) & " " Next cell oData.SetText sText oData.PutInClipboard End Sub It takes the selected cells, convert them to a string and write this string in the clipbboard. Then you can past it where ever you want. "OTS" wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Great!
I just changes "SelectedRange" to Selecteion and it worked like a dream. Now I guess I have to do some error cheking so that I can be sure that the Cell values come from the desired column. Thanks man! Regards OTS " wrote: Hi This will put your string on sheet "mydata" in cell "A1". The selected cells can be anywhere on the active sheet, and you would need further error checking if you want to restrict people to one particular column. Names will be seperated by commas, but you can change this below. you will get an error if no cells are selected. Sub tester3() Dim Cell As Range Dim mystring As String For Each Cell In SelectedRange mystring = mystring & ", " & Cell.Text Next Cell 'take off leading 2 characters ", " mystring = Right(mystring, Len(mystring) - 2) Worksheets("mydata").Range("a1").Value = mystring End Sub regards Paul On May 11, 9:24 am, OTS wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Sorry, I've not seen the last answer ....
"Michi" wrote: Hi ! I have made a litlle programm fpr your problem. Create a button and write code like you see here in the modul: Sub Button1_Click() Dim oData As New DataObject Dim sText As String For Each cell In Selection.Cells On Error Resume Next 'ignore all errors sText = sText & CStr(cell.Value) & " " Next cell oData.SetText sText oData.PutInClipboard End Sub It takes the selected cells, convert them to a string and write this string in the clipbboard. Then you can past it where ever you want. "OTS" wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
Thanks man. I'll give it a try. :-)
Regards OTS "Michi" wrote: Hi ! I have made a litlle programm fpr your problem. Create a button and write code like you see here in the modul: Sub Button1_Click() Dim oData As New DataObject Dim sText As String For Each cell In Selection.Cells On Error Resume Next 'ignore all errors sText = sText & CStr(cell.Value) & " " Next cell oData.SetText sText oData.PutInClipboard End Sub It takes the selected cells, convert them to a string and write this string in the clipbboard. Then you can past it where ever you want. "OTS" wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
On May 11, 1:49 pm, OTS wrote:
Great! I just changes "SelectedRange" to Selecteion and it worked like a dream. Now I guess I have to do some error cheking so that I can be sure that the Cell values come from the desired column. Thanks man! Regards OTS " wrote: Hi This will put your string on sheet "mydata" in cell "A1". The selected cells can be anywhere on the active sheet, and you would need further error checking if you want to restrict people to one particular column. Names will be seperated by commas, but you can change this below. you will get an error if no cells are selected. Sub tester3() Dim Cell As Range Dim mystring As String For Each Cell In SelectedRange mystring = mystring & ", " & Cell.Text Next Cell 'take off leading 2 characters ", " mystring = Right(mystring, Len(mystring) - 2) Worksheets("mydata").Range("a1").Value = mystring End Sub regards Paul oops, sorry about that, I pasted one I was working on - selection is right. Paul On May 11, 9:24 am, OTS wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS- Hide quoted text - - Show quoted text - |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro for using multiple selected cells
No prob. I guess your approach is somewhat better since I can use it for
severel other tasks. I have tried it, but the "new DataObject" dosent seem to work. I guess it is my lack of knowledge on this subject that dosen't get it to work though.. Regards OTS "Michi" wrote: Sorry, I've not seen the last answer .... "Michi" wrote: Hi ! I have made a litlle programm fpr your problem. Create a button and write code like you see here in the modul: Sub Button1_Click() Dim oData As New DataObject Dim sText As String For Each cell In Selection.Cells On Error Resume Next 'ignore all errors sText = sText & CStr(cell.Value) & " " Next cell oData.SetText sText oData.PutInClipboard End Sub It takes the selected cells, convert them to a string and write this string in the clipbboard. Then you can past it where ever you want. "OTS" wrote: Hi! I have no experience with programming macros so bear with me. I'm not sure if my case is possible to do in some easy way. I want the user to be able to select some cells in a coulmn Users in a worksheet. This selection will then be concatenated to a string of Usernaes and inserted in a user-selected cell in another worksheet. -- OTS |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Stop multiple cells from being automatically selected | Excel Discussion (Misc queries) | |||
why are multiple cells selected when i only want one? | Excel Discussion (Misc queries) | |||
Multiple cells or columns are selected instead of selected cell or | Excel Discussion (Misc queries) | |||
why do multiple cells get selected when i click only one cell? | Excel Discussion (Misc queries) | |||
Macro to take selected cells times a selected cell | Excel Programming |