Solved

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

Posted on 2014-10-21
5
121 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now