Astuce: Les autres langues sont Google-Traduction. Vous pouvez visiter le English version de ce lien.
Se connecter
x
or
x
x
S'enregistrer
x

or

Comment créer un bouton de commande pour copier et coller des données dans Excel?

Supposons que vous ayez besoin de copier fréquemment une plage de cellules à un autre endroit après avoir modifié les données, la méthode de copier-coller manuelle sera fastidieuse et fastidieuse. Comment faire fonctionner cette affaire de copier-coller automatiquement? Cet article va vous montrer comment utiliser un bouton de commande pour copier et coller des données en un seul clic.

Créer un bouton de commande pour copier et coller des données avec du code VBA

Onglet Office Activer l'édition et la navigation par onglets dans Office, et simplifiez grandement votre travail ...
Kutools for Excel résout la plupart de vos problèmes et augmente votre productivité de 80%
  • Réutiliser n'importe quoi: Ajoutez les formules, graphiques et autres éléments les plus utilisés ou les plus complexes à vos favoris et réutilisez-les rapidement.
  • Plus que le texte 20 comprend: Extraire le numéro de la chaîne de texte; Extraire ou supprimer une partie des textes; Convertissez les nombres et les devises en mots anglais.
  • Fusionner les outils: Plusieurs classeurs et feuilles en un; Fusionner plusieurs cellules / lignes / colonnes sans perdre de données; Fusionner les lignes en double et la somme.
  • Outils Split: Fractionner les données en plusieurs feuilles en fonction de la valeur; Un classeur pour plusieurs fichiers Excel, PDF ou CSV; Une colonne à plusieurs colonnes.
  • Coller Sauter Lignes cachées / filtrées; Compte et somme par couleur de fond; Envoyez des e-mails personnalisés à plusieurs destinataires en bloc.
  • Super filtre: Créez des schémas de filtrage avancés et appliquez-les à toutes les feuilles. Trier par semaine, jour, fréquence et plus; Filtre en gras, formules, commentaires ...
  • Plus que de puissantes fonctionnalités 300; Fonctionne avec Office 2007-2019 et 365; Prend en charge toutes les langues; Déploiement facile dans votre entreprise ou organisation.

Créer un bouton de commande pour copier et coller des données avec du code VBA


Veuillez procéder comme suit pour copier et coller des données automatiquement lorsque vous cliquez sur un bouton de commande.

1. Insérer un bouton de commande en cliquant Développeur > insérer > Bouton de commande (contrôle ActiveX). Voir la capture d'écran:

2. Dessinez un bouton de commande dans votre feuille de calcul et faites un clic droit dessus. Sélectionner Voir le code dans le menu contextuel.

3. Dans le popping up Microsoft Visual Basic pour applications fenêtre, s'il vous plaît remplacer le code d'origine dans la fenêtre Code avec ci-dessous le code VBA.

Code VBA: utilisez le bouton de commande pour copier et coller des données dans Excel

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Dim xSheet As Worksheet
    Set xSheet = ActiveSheet
        If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
            xSheet.Range("A1:C17 ").Copy
            xSheet.Range("J1:L17").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End If

    Application.ScreenUpdating = True
End Sub

Note: Dans le code, CommandButton1 est le nom de votre bouton de commande inséré. A1: C17 est la plage que vous devez copier, et J1: L17 est la plage de destination pour coller des données. S'il vous plaît, changez-les selon vos besoins.

4. presse autre + Q les clés pour fermer le Microsoft Visual Basic pour applications fenêtre. Et désactivez le mode Création sous l'onglet Développeur.

5. Maintenant, cliquez sur le bouton de commande, toutes les données dans la gamme A1: C17 seront copiés et collés dans la gamme J1: L17 sans la mise en forme des cellules.


Articles connexes:


Kutools for Excel résout la plupart de vos problèmes et augmente votre productivité de 80%

  • Réutilisation: Insérer rapidement formules complexes, graphiques et tout ce que vous avez utilisé auparavant; Crypter les cellules avec mot de passe Créer une liste de diffusion et envoyer des emails ...
  • Super Formula Bar (éditez facilement plusieurs lignes de texte et de formule); Disposition de lecture (facilement lire et éditer un grand nombre de cellules); Coller à la gamme filtrée...
  • Fusionner les cellules / rangées / colonnes sans perdre de données; Contenu des cellules divisées; Combiner les lignes / colonnes en double... Prévenir les cellules en double; Comparer les plages...
  • Sélectionnez Dupliquer ou Unique Des rangées; Sélectionnez les lignes vierges (toutes les cellules sont vides); Super Find et Fuzzy Find dans de nombreux cahiers d'exercices; Sélection aléatoire ...
  • Copie exacte Plusieurs cellules sans changer la référence de la formule; Créer automatiquement des références à plusieurs feuilles; Insérer des balles, Cases à cocher et plus ...
  • Extrait du texte, Ajouter du texte, Supprimer par position, Supprimer l'espace; Créer et imprimer des sous-totaux de pagination; Conversion entre contenu de cellules et commentaires...
  • Super filtre (enregistrer et appliquer des schémas de filtrage à d'autres feuilles); Tri avancé par mois / semaine / jour, fréquence et plus; Filtre spécial en gras, en italique ...
  • Combinaison de classeurs et de feuilles de calcul; Fusionner les tables en fonction des colonnes clés; Fractionner les données en plusieurs feuilles; Conversion par lots xls, xlsx et PDF...
  • Plus que de puissantes fonctionnalités 300. Prend en charge Office / Excel 2007-2019 et 365. Prend en charge toutes les langues. Déploiement facile dans votre entreprise ou organisation. Fonctionnalités complètes Essai gratuit du jour 30.
kte tab 201905

Office Tab apporte une interface à onglets à Office et simplifie grandement votre travail

  • Activer l'édition par onglets et la lecture dans Word, Excel, PowerPoint, Publisher, Access, Visio et Project.
  • Ouvrez et créez plusieurs documents dans de nouveaux onglets de la même fenêtre, plutôt que dans de nouvelles fenêtres.
  • Augmente votre productivité de 50% et réduit le nombre de clics de souris pour vous chaque jour!
fond officetab
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Abi · 1 months ago
    This is fab - i've adapted for my s.sheet but I need it to be more dynamic and use labels rather than hard code the cell locations.
    I.e in the range of A2-A6 find the name 'Jamie' and then find the name in Column K2 and paste

    I also need each click to +1 and run the same copy and paste but to the next column i.e.

    click 1 - pastes into Q1, Click 2 - paste into Q2 etc

    Example:

    Column A Column B ...... Column K Column L
    1. Name Hrs worked Name Q1 Q2 Q3 Q4
    2. Jamie 22 Sammy <Paste here>
    3. Sammy 40 Judith <Paste here>
    4. Judith 18 Jamie <Paste here>
    5. Tammy 16 Keith <Paste here>
    6. Keith 42 Tammy <Paste here>


    Any help would be greatly appreciated.
  • To post as a guest, your comment is unpublished.
    Jonas · 2 months ago
    Hello!
    Is there a way to make a code so i can have a button copy a range (lets say A1:D5).
    And then paste it to A6:D10.

    And if i press the button once more it will copy A1:D5 to A11:D15.

    And so on?
  • To post as a guest, your comment is unpublished.
    Lexi · 2 months ago
    Is it possible to make a button that just copies one selected cell on one sheet to another sheet? Thanks!
    • To post as a guest, your comment is unpublished.
      crystal · 2 months ago
      Hi lexi,
      The below VBA code can help you solve the problem. Please change "Sheet3" to the sheet name as you need.
      Select a cell and press the command button to make it work.

      Private Sub CommandButton1_Click()
      Dim xSWName As String
      Dim xSheet As Worksheet
      Dim xPSheet As Worksheet
      Dim xIntR As Integer
      xSWName = "Sheet3"
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xSheet = ActiveSheet
      If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
      Selection.CurrentRegion.Select
      Selection.Copy
      Set xPSheet = Worksheets.Item(xSWName)
      xIntR = xPSheet.UsedRange.Rows.Count
      xPSheet.Cells(xIntR + 1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      End If
      Application.ScreenUpdating = True
      End Sub
  • To post as a guest, your comment is unpublished.
    S J · 3 months ago
    please send VBAcode for copy single cell content using commmand button click without using text box so tha will be able to paste in any application like notepad,msword
  • To post as a guest, your comment is unpublished.
    angela · 5 months ago
    master bagaimana jika berbeda sheet dan copy data yg diinginkan
    contoh sheet1 hanya data kolom B & kolom D copy ke sheet2
    terimakasih
  • To post as a guest, your comment is unpublished.
    Ted Jillett · 6 months ago
    I'm looking for some help on that a user can click on a row number and then hit the command button that it will make a copy of that row and insert it into the row below it.
    • To post as a guest, your comment is unpublished.
      crystal · 4 months ago
      Good day,
      Sorry can help you with that yet. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Yesaya · 7 months ago
    hi, help my case, i want have a button to generate macro where i have excel and export the data where in the <" "> to word, thanks
    • To post as a guest, your comment is unpublished.
      crystal · 6 months ago
      Hi,
      Sorry I didn't get your point. Would be nice if you could explain with more details of what you are trying to do.
  • To post as a guest, your comment is unpublished.
    Kyaw Ye Min · 7 months ago
    Hi Author,

    The article you mentioned above is very helpful to me. I am not used to excel code and command. I still need to know rather than this article. I am ok with the copy and paste into next sheet. But I still need to know "how to paste and add into new line in next sheet every time I press the button". Otherwise, my data on next sheet will be replaced every time. I would really be grateful and looking forward to see your reply.
    • To post as a guest, your comment is unpublished.
      crystal · 4 months ago
      Hi Kyaw Ye Min,
      Sorry for replying so late. Follow the steps and replace the code with the below. In the code, Sheet4 is the destination worksheet you will copy data into, please change it and the copied range A1:C17 as you need. Thanks for your comment.

      Private Sub CommandButton1_Click()
      Dim xSWName As String
      Dim xSheet As Worksheet
      Dim xPSheet As Worksheet
      Dim xIntR As Integer
      xSWName = "Sheet4"
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xSheet = ActiveSheet
      If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
      xSheet.Range("A1:C17 ").Copy
      Set xPSheet = Worksheets.Item(xSWName)
      xIntR = xPSheet.UsedRange.Rows.Count
      xPSheet.Cells(xIntR + 1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      End If
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Chris · 3 months ago
        Hi there please help. I require the same as above but i just need to paste whatever the active cell is into a new line (if possible above previous entries) in a different worksheet. Really appreciate any help with this. Best Regards
  • To post as a guest, your comment is unpublished.
    Jim · 8 months ago
    I have a qusrion I have sheet 1 with a column of date b3:b33 and I want that to be copied to sheet 2 B33:b63 its text but I need the same format for text ie colour size
  • To post as a guest, your comment is unpublished.
    Robbert · 8 months ago
    If I want to Copy this not in the current workbook but into another workbook (which is still not opened) in excel. How do I change this VBA code accordingly?
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi Robbert,
      Sorry can't help you with that. Thanks for commenting.
  • To post as a guest, your comment is unpublished.
    MangkaNorr · 10 months ago
    sir how to copy the range of the cell in current worksheet then paste to another worksheets ?
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Hi,
      The below VBA code can help you solve the problem.
      You need to replace the "Sheet4" and "A1:C17" in the code with your specified sheet and range.

      Private Sub CommandButton1_Click()
      Dim xSWName As String
      Dim xSheet As Worksheet
      Dim xPSheet As Worksheet
      Dim xIntR As Integer
      xSWName = "Sheet4"
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xSheet = ActiveSheet
      If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
      xSheet.Range("A1:C17 ").Copy
      Set xPSheet = Worksheets.Item(xSWName)
      xIntR = xPSheet.UsedRange.Rows.count
      xPSheet.Cells(xIntR + 1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      End If
      Application.ScreenUpdating = True
      End Sub
  • To post as a guest, your comment is unpublished.
    Adam · 1 years ago
    Would it be possible to for the command button to instantly paste the selected range to a specified sheet (in the next empty cell) rather than having to input each time where you want to paste the data?
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Hi Adam,
      The below VBA code can help you solve the problem.
      You need to replace the "Sheet4" and "A1:C17" in the code with your specified sheet and range.

      Private Sub CommandButton1_Click()
      Dim xSWName As String
      Dim xSheet As Worksheet
      Dim xPSheet As Worksheet
      Dim xIntR As Integer
      xSWName = "Sheet4"
      On Error Resume Next
      Application.ScreenUpdating = False
      Set xSheet = ActiveSheet
      If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
      xSheet.Range("A1:C17 ").Copy
      Set xPSheet = Worksheets.Item(xSWName)
      xIntR = xPSheet.UsedRange.Rows.count
      xPSheet.Cells(xIntR + 1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      End If
      Application.ScreenUpdating = True
      End Sub
      • To post as a guest, your comment is unpublished.
        Mohamed shoman · 9 months ago
        very good , i need to copy and paste many time is it possible to make a choice to paste a row of data to 3 rows or 5 rows whatever i like ?
  • To post as a guest, your comment is unpublished.
    Jeff McCollum · 1 years ago
    I would like to expand this one step... After pasting the actual values not formulas... I need to copy the new cell and paste in another program that's not excel, should simply I need to click the button copy the formula from a specific cell and past the actual value in another, then copy that new value to windows clipboard to past in another app. Hope this make sense, and appreciate your help in knowing how to add the new code... I know what I want it to do, just not familiar with how to code it...
    Thanks
    • To post as a guest, your comment is unpublished.
      crystal · 11 months ago
      Hi,
      The code has been updated in the article, please have a try. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    Magnus · 1 years ago
    What if I would like to make a paste queue?
    To explain further. I click CommandButton1 then it copy A1. When I have used paste, the copy from A1 - Then I want to copy A2 without clicking another button, so that I can paste A2 right away, somewhere else. Then When I have used paste, the copy from A2 then copy A3. If that is possible? Can this also work in the background when use a normal Excel sheet, and try to do this action where I copy from Excel, and then paste in a completely different program like a internet browser, another program, word, txt file, and so on?

    This article was anyway extremely helpful, thank you so much!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Magnus,
      Sorry can't help you with that. Thanks for your comment.
  • To post as a guest, your comment is unpublished.
    Azam as · 1 years ago
    how is the formula for us to copy files
    then paste it to the next sheet. and paste the next one make a space or keep going down without deleting the previous paste.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good day,
      The below VBA code can help you solve the problem. Please have a try. Thank you.

      Private Sub CommandButton1_Click()
      Dim xSheet, xDWS As Worksheet
      Dim xFNum As Integer
      Dim xSRg As Range

      On Error Resume Next
      Set xSRg = Application.InputBox("Please select cell to paste the range:", "Kutools for Excel", xTxt, , , , , 8)
      If xSRg Is Nothing Then Exit Sub

      Application.ScreenUpdating = False
      Range("A1:C17 ").Copy
      xSRg.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      Application.ScreenUpdating = True

      End Sub
  • To post as a guest, your comment is unpublished.
    Jason · 1 years ago
    How can you alter the code to paste the results to another page with in the workbook? and how do you get the insert a row before putting the new data in so it does not overwrite it
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi Jason,
      If you want to paste the results to another worksheets within the workbook, please try the below VBA code.

      Private Sub CommandButton1_Click()
      Dim xSheet, xDWS As Worksheet
      Dim xFNum As Integer
      Dim xSRg As Range

      On Error Resume Next
      Set xSRg = Application.InputBox("Please select cell to paste the range:", "Kutools for Excel", xTxt, , , , , 8)
      If xSRg Is Nothing Then Exit Sub

      Application.ScreenUpdating = False
      Range("A1:C17 ").Copy
      xSRg.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
      Application.ScreenUpdating = True

      End Sub
  • To post as a guest, your comment is unpublished.
    Dom · 2 years ago
    I have used this function in my workbook. I am using active x buttons to copy and paste data within the same sheet on multiple sheets. However there are sheets without active x buttons or macros that get pasted data from the respective fields on the sheet which I don't want. Help?