• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Split a cell by clicking on the cell

Split a cell by clicking on the cell
0
cd_morris
Asked:
cd_morris
  • 3
1 Solution
 
zorvek (Kevin Jones)ConsultantCommented:
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
 
cd_morrisAuthor Commented:
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
 
zorvek (Kevin Jones)ConsultantCommented:
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
 
zorvek (Kevin Jones)ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now