Vai al contenuto principale

Come inserire automaticamente una nuova riga vuota dal pulsante di comando in Excel?

In molti casi, potrebbe essere necessario inserire una nuova riga vuota in una posizione specificata del foglio di lavoro. In questo articolo, ti mostreremo come inserire automaticamente una nuova riga vuota facendo clic su un pulsante di comando in Excel.

Inserisci automaticamente una nuova riga vuota dal pulsante di comando


Inserisci automaticamente una nuova riga vuota dal pulsante di comando

È possibile eseguire il seguente codice VBA per inserire una nuova riga vuota facendo clic su un pulsante di comando. Si prega di fare quanto segue.

1. Innanzitutto, è necessario inserire un pulsante di comando. Fare clic su Costruttori > inserire > Pulsante di comando (controllo ActiveX). Vedi screenshot:

2. Quindi disegnare un pulsante di comando nel foglio di lavoro necessario per aggiungere nuove righe, fare clic con il pulsante destro del mouse sul pulsante di comando e fare clic Properties dal menu di scelta rapida.

3. Nel Properties finestra di dialogo, immettere il testo visualizzato del pulsante di comando nel file Didascalia scatola sotto il Classificato scheda e quindi chiudere la finestra di dialogo.

Puoi vedere che il testo visualizzato del pulsante di comando è cambiato come mostrato nell'immagine sottostante.

4. Fare nuovamente clic con il pulsante destro del pulsante di comando e quindi scegliere Visualizza codice dal menu di scelta rapida.

5. Quindi il file Microsoft Visual Basic, Applications Edition finestra, sostituire il codice originale con il codice VBA sottostante nel file Code finestra.

Codice VBA: inserisci automaticamente una nuova riga vuota tramite il pulsante di comando

Private Sub CommandButton1_Click()
    Dim rowNum As Integer
    On Error Resume Next
    rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
                                    Title:="Kutools for excel", Type:=1)
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
End Sub

Note:: Nel codice, CommanButton1 è il nome del pulsante di comando che hai creato.

6. Stampa altro + Q contemporaneamente i tasti per chiudere il file Microsoft Visual Basic, Applications Edition finestra. E disattiva il Modalità di progettazione sotto il Costruttori scheda.

7. Fare clic sul pulsante di comando inserito e a Kutools for Excel si apre la finestra di dialogo. Immettere un determinato numero di riga in cui si desidera aggiungere una nuova riga vuota, quindi fare clic su OK pulsante. Vedi screenshot:

Quindi la nuova riga vuota viene inserita in una posizione specificata del foglio di lavoro come mostrato nell'immagine sottostante. E mantiene la formattazione della cella della cella sopra.


Articoli correlati:

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (26)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Bedankt voor je uitleg. Ik heb de formule toegepast maar bekom dat ik maar 1 lijn kan toevoegen. Daarna laat de knop het niet meer toe en moet ik eerst mijn toegevoegde rij verwijderen. Is er een manier om dit aan te passen?
This comment was minimized by the moderator on the site
Is there a way to make to row inset always below the last entry?
This comment was minimized by the moderator on the site
How do I do the opposite of this and create a button that will delete a row?
This comment was minimized by the moderator on the site
Hi Big Ant,

Here's the modified code to delete a specified row when the Command Button is clicked:


Private Sub CommandButton1_Click()
'Updated by Extendoffice 20230817
    Dim rowNum As Integer
    On Error Resume Next
    rowNum = Application.InputBox(Prompt:="Enter Row Number which you want to delete:", _
                                    Title:="Kutools for excel", Type:=1)
    If rowNum <> 0 Then
        Rows(rowNum).Delete Shift:=xlUp
    End If
End Sub
This comment was minimized by the moderator on the site
Criei uma linha e nomeei como spotB,
Mudei a altura da linha para 0,01 para ocultá-la (apenas por estética).
Criei um botão:
Application.Goto Reference:="spotB"
Selection.EntireRow.Insert

Problema resolvido.

Obrigado pelos códigos a Mah e crystal, mas eu tinha 8 títulos para separar, cada um inserindo linhas quando necessário ao usuário, e não queria nenhuma pergunta sobre quantidade de linhas, os usuários não leem perguntas e clicam logo em OK, depois reclamam...
This comment was minimized by the moderator on the site
... Testei os códigos acima, mas, como se trata de pessoas que vão usar, não é viável os box que pedem a linha e a quantidade, não dá...
This comment was minimized by the moderator on the site
Caros colegas, após pesquisar (bastante) na net não consegui encontrar um atalho, comando, código, nada, nada, que eu possa usar para inserir em uma macro APENAS uma forma de inserir uma linha ABAIXO da célula ativa. Isto porquê se eu gravar o endereço da célula, ele não muda, fica sempre na mesma célula e as seguintes não vão ficar corretamente abaixo, e se eu usar um endereço de célula fixo, a linha tem que ser inserida acima, mas não formata da forma desejada, que seria o formato das linhas de cima.

Acho que o código existe, só não encontro, já tentei várias formas, selecionando um fixo, subindo uma linha e pedindo para inserir após, mas as seguintes não funcionam de acordo.

Alguém poderia me ajudar?
This comment was minimized by the moderator on the site
Hi

I used the code but wanted to add rows with formulas, therefore I added the last line to be able to add the rows with formulas.
However, in my excel file and in column "F" I have a text which can be entered manually and would be different in different cases. Therefore, I would like to add rows below the reference row with keeping the formulas and values in all cells except the cell from column "F" which I would like to be copied as blank!
Could you please help me with what should I add to the underneath code to be able to have the cells of column "F" blank whenever I add a row with this code?
thanks in advance!

Private Sub CommandButton1_Click()
Dim xIntRrow As Integer
Dim rowNum As Integer
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
Title:="Kutools for excel", Type:=1)
xIntRrow = Application.InputBox(Prompt:="Type in the number of rows you want to insert", _
Title:="Kutools for excel", Type:=1)
Rows(rowNum + 1 & ":" & rowNum + 1).EntireRow.Resize(xIntRrow).Insert Shift:=xlShiftDown
Rows(rowNum).Resize(xIntRrow + 1).FillDown

End Sub
This comment was minimized by the moderator on the site
Hi Mah,
The following VBA code may do you a favor. Please give it a try. Thank you.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20220707
    Dim rowNum As Integer
    Dim xRg1, xRg2 As Range
    
    On Error Resume Next
    
    rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
                                    Title:="Kutools for excel", Type:=1)
    
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
    Rows((rowNum - 1) & ":" & (rowNum - 1)).Copy
    Rows(rowNum & ":" & rowNum).Select
    Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
    Range("F" & rowNum).Value = ""
End Sub
This comment was minimized by the moderator on the site
Sub AddNewRow()



Private Sub CommandButton1_Click()

ActiveSheet.Unprotect Password:="1234"



Dim mySheets

Dim i As Long



mySheets = Array("Sheet2")



For i = LBound(mySheets) To UBound(mySheets)

With Sheets(mySheets(i))

.Range("B10").EntireRow.Insert Shift:=xlDown

.Range("B10:H10").Borders.Weight = xlThin

End With

Next i



ActiveSheet.Protect Password:="1234"



End Sub

I don't know if this will work for you. It worked quite well for me. I even left unprotected cells that you can input data and the formulas are still active. Took me a whole day to figure it out. replace "1234" with whatever password you feel like, "Sheet2" with the Sheet you are working with and input the range you want.
The code first unprotects the worksheet, adds row and protects the worksheet.
This comment was minimized by the moderator on the site
is it possible to create in a different sheet? I really need that
This comment was minimized by the moderator on the site
can possible insert multiple sheet row at one time click by this .
This comment was minimized by the moderator on the site
Hi,
The below code can help you solve the problem. Please have a try.

Private Sub CommandButton1_Click()
Dim xIntRrow As Integer
Dim rowNum As Integer
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
Title:="Kutools for excel", Type:=1)
xIntRrow = Application.InputBox(Prompt:="Type in the number of rows you want to insert", _
Title:="Kutools for excel", Type:=1)
Rows(rowNum + 1 & ":" & rowNum + 1).EntireRow.Resize(xIntRrow).Insert Shift:=xlShiftDown

End Sub
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations