Solved

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

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

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 45

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 45

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

762 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

19 Experts available now in Live!

Get 1:1 Help Now