Solved

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

Posted on 2014-10-21
5
133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 48

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 48

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

691 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