+ Reply to Thread
Results 1 to 5 of 5

Macro to add text to a cell in another workbook which may already contain text

  1. #1
    Registered User
    Join Date
    03-30-2016
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    93

    Macro to add text to a cell in another workbook which may already contain text

    Hi,

    I'm trying to create a tool which will allow common phrases/responses which are listed in a spreadsheet to be copied to a cell in another worksheet.

    I have buttons at the side of the phrases/responses and my intention was to simply press the button and this would copy the text across.

    It works fine when you are using just one response, the text copies over just fine, but there are certain circumstances where I might need to use 2 or more of these common responses at the same time, and when I tried to copy/paste more than 1 I got a debug error or nothng at all happened and the only text in the cell being pasted to was the original text copied into it.

    I hope that makes sense. Any advice much appreciated.

  2. #2
    Valued Forum Contributor meabrams's Avatar
    Join Date
    10-03-2014
    Location
    USA
    MS-Off Ver
    2007, 2010, 2013, 2016
    Posts
    451

    Re: Macro to add text to a cell in another workbook which may already contain text

    would it be possible for you to post macro so that we can see what I causing the error

  3. #3
    Registered User
    Join Date
    03-30-2016
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    93

    Re: Macro to add text to a cell in another workbook which may already contain text

    Hi, this is the macro

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
    Range("A1").Select
    Selection.Copy
    Windows("XXXXXv5 2.xlsm").Activate
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    End Sub
    Sub Macro2()
    '
    ' Macro2 Macro
    '

    '
    Range("A1").Select
    Selection.Copy
    Windows("XXXXXv5 2.xlsm").Activate
    Range("C4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    End Sub
    I've just tried re-doing the macro so this is the most recent one.

    Just retried and I get no error now, but if I was to select button 1(macro1) it would paste into the required cell, then if I select button 2 (macro2) it erases whats in the cell and replaces it with the text copied for macro2

  4. #4
    Registered User
    Join Date
    03-30-2016
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    93

    Re: Macro to add text to a cell in another workbook which may already contain text

    OK, a bit of research and I've come up with this

    Sub Macro9()

    'Application.ScreenUpdating = False


    Text = Range("A3")
    Windows("XXXXX v5 2.xlsm").Activate

    Dim i As Range
    Range(Range("C4"), Range("C4").End(xlDown)).Select

    For Each i In Selection
    i.Value = Text & i.Value
    Next i

    End Sub
    Now I get the following error

    Run-time error '1004'

    The cell or chart you're trying to change is on a protected sheer.

    To make changes, click Unprotect Sheet in the Review tab (you might need a password)
    The worksheet being posted to is protected, but the cell being posted to in this worksheet is not.

    The text now does copy to the cell and it doesn't remove the text already in there, the only problem now is this error which is a little annoying.

    Other than removing the protection from the sheet is there anything else I can do?

    Thanks all.

  5. #5
    Registered User
    Join Date
    03-30-2016
    Location
    Manchester
    MS-Off Ver
    2013
    Posts
    93

    Re: Macro to add text to a cell in another workbook which may already contain text

    Any help appreciated

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro that will insert a simple text string in top cell of text file
    By Davek11 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2014, 07:31 PM
  2. Macro to automatically convert prt scr image-based text to real text in cell
    By jasonfromchico in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2014, 02:27 PM
  3. Replies: 3
    Last Post: 02-14-2014, 08:08 AM
  4. Using macro to locate certain text, then copy the cell below text into another sheet
    By BobertSama in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-12-2013, 01:32 PM
  5. Replies: 13
    Last Post: 11-29-2012, 08:25 PM
  6. Macro to convert a mutiple sheet workbook to tab delimited text or fixed width text file
    By chandra 2185 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-05-2012, 10:29 AM
  7. Need a macro to insert text in a cell that already has text.Excel
    By go1angel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2005, 02:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1