Results 1 to 6 of 6

Thread: How to Copy Text in a cell using the Command Button?

  1. #1
    Join Date
    Aug 2006
    Posts
    155

    How to Copy Text in a cell using the Command Button?

    I want the code for the command button that can copy the text in a cell of Sheet1 to the text box of Sheet2. Or the command button to move data from the cells in a Column of Sheet1 to the Row of Sheet2. Please help me if somebody knows the coding.!!
    Desktop * Athlon X2 4200 | 2048M RAM | 160G HD | 7600GT
    MacMini * G4 1.33GHz | 512M RAM | 40G HD | Radeon 9200
    Laptop * Sempron 2800 | 512M RAM | 60G HD
    PDA * Dell Axim x51 | 128M Internal | 256M SD Card

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How to Copy Text in a cell using the Command Button?

    I think that this code should work for you..
    Sheet1 has the text box (let it be txtOut) and the Sheet2 has to the cell (let it be B4) that has to be copied. Also the command button be cmdCopy. The code should be like this :

    Private Sub cmdCopy_Click()

    Sheet1.txtOut.Text = ""
    Sheet1.txtOut.Text = Sheet2.Range("B4").Value

    End Sub

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to Copy Text in a cell using the Command Button?

    I think that code mentioned by the "Zecho" should work. I have not checked that code personally but the logic used seems to be correct. Just make sure that you are giving the Exact cell that has to copied in the coding. Otherwise you will get the unexpected answer. I think that you can use the same logic for copying the columns and rows to the other sheets.

  4. #4
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to Copy Text in a cell using the Command Button?

    You can also use the Macro for copying the Columns of Sheet1 to the Rows of Sheet2 by using the following code :

    Sub Macro1()

    Sheets("Sheet1").Select
    Range("B34:B41").Select
    Selection.Copy

    Sheets("Sheet2").Select
    Range("A65536").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
    SkipBlanks:= _
    False, Transpose:=True

    Sheets("Sheet1").Select
    Range("B34:B41").Select
    Application.CutCopyMode = False
    Selection.ClearContents

    End Sub

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Copy Text in a cell using the Command Button?

    I think that the following code will also help you to get the desired answer :
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
    SkipBlanks:= False, Transpose:=True
    If the other code is not working you can try this. According to me it should work properly.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to Copy Text in a cell using the Command Button?

    If you want to copy the duplicate text from one textbox on a form to another textbox using the Command Button, you can use the following code :

    me.[ControlB] = me.[ControlA]

    which assumes that names of the controls are ControlA and ControlB.
    You have to place this event code on the OnClick event of your command button, so that it can copy the text from ControlA to ControlB.

Similar Threads

  1. How to use VLOOKUP IF in cell that contains Text
    By RYAN$ in forum MS Office Support
    Replies: 2
    Last Post: 11-01-2012, 04:06 PM
  2. copy a hyperlink to another cell
    By aya2002 in forum Windows Software
    Replies: 2
    Last Post: 21-03-2010, 03:37 AM
  3. Auto-populate a MS Word table cell with text from a diff cell?
    By dreamrthts in forum Windows Software
    Replies: 5
    Last Post: 23-03-2009, 10:39 PM
  4. Replies: 0
    Last Post: 18-03-2009, 10:00 PM
  5. Command prompt "COPY" command not working in brand new Windows Vis
    By CMD COPY command not working in Vista in forum Vista Help
    Replies: 7
    Last Post: 06-02-2008, 02:50 AM

Tags for this Thread

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
  •  
Page generated in 1,713,526,632.75175 seconds with 17 queries