Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Split a cell by clicking on the cell

Posted on 2011-04-27
4
Medium Priority
?
218 Views
Last Modified: 2012-05-11
Split a cell by clicking on the cell
0
Comment
Question by:cd_morris
  • 3
4 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35478341
Can you provide a few more details? What is in the cell? How do you want it split? A split implies splitting a cell into multiple cells - which cells do you want to get the results of the split?

Kevin
0
 
LVL 4

Author Comment

by:cd_morris
ID: 35478824
Kevin, this is a follow up question to Q_26976800.html

I have data in cell example D1 (but could change) that looks like the following:

1. This is a test.
2. This is another test.

I want to be able to double click on the cell and have the data split to have :
"1. This is a test." in one cell and "2. This is another test." in the cell under it.
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 total points
ID: 35478859
Add this code to the worksheet code module.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim Lines As Variant
    Lines = Split(Target.Value, vbLf)
    Target.Resize(UBound(Lines) + 1).Value = Application.Transpose(Lines)

End Sub

You don't need any of the code from the other question to do this.

Kevin
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 35478911
This one is a little more robust and will handle a cell with multiple sentences without line feeds:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim Lines As Variant
    If Len(Target) > 0 Then
        Lines = Split(Replace(Target.Value, vbLf, " "), ". ")
        Target.Resize(UBound(Lines) + 1).Value = Application.Transpose(Lines)
    End If

End Sub

Kevin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question