Solved

Entering a string into a cell without deleting what is already there

Posted on 2014-10-21
5
124 Views
Last Modified: 2014-10-21
I need a piece of code that will go into the cell I have highlighted, enter a string of text, insert a carriage return, and then leave the cell.

Every time I try to do this, it deletes the text that is already in the cell. What I need for the code to do is just insert the string above the text that is already there.

Is this possible?
0
Comment
Question by:Megin
5 Comments
 
LVL 12

Expert Comment

by:tel2
ID: 40395837
Hi Megin,

> What I need for the code to do is just insert the string above the text that is already there.

Q1. What do you mean by "above" in this context?
Q2. Is the "string of text" to be inserted always the same text, or what?
Q3. And what version of Excel are you using?
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40395839
Range(<my cell's address>).Value = "New String" & vbcrlf & Range(<my cell's address>).Value
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40395840
Here is the code for the selected range will do the requested:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A2:A25")) Is Nothing Then
  Dim copy As String
  
  copy = Target.value
  Target.value = "SAMPLE" & Chr(10) & copy
   
End If
End Sub

Open in new window


Code will run on the double click in the defined range
0
 

Author Closing Comment

by:Megin
ID: 40395864
That worked perfectly!

THANK YOU!!!!

(And thank you to the rest of you who answered!)
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40395882
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

773 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