메인 컨텐츠로 가기

Excel에서 명령 단추로 빈 새 행을 자동으로 삽입하는 방법은 무엇입니까?

대부분의 경우 워크 시트의 지정된 위치에 빈 새 행을 삽입해야 할 수 있습니다. 이 기사에서는 Excel에서 명령 단추를 클릭하여 빈 새 행을 자동으로 삽입하는 방법을 보여줍니다.

명령 단추로 빈 새 행을 자동으로 삽입


명령 단추로 빈 새 행을 자동으로 삽입

다음 VBA 코드를 실행하여 명령 단추를 클릭하여 빈 새 행을 삽입 할 수 있습니다. 다음과 같이하십시오.

1. 먼저 Command Button을 삽입해야합니다. 클릭하세요 개발자 > 끼워 넣다 > 명령 단추 (ActiveX 컨트롤). 스크린 샷보기 :

2. 그런 다음 새 행을 추가해야하는 워크 시트에 명령 단추를 그리고 명령 단추를 마우스 오른쪽 단추로 클릭하고 등록 오른쪽 클릭 메뉴에서.

3. 에서 등록 대화 상자에서 명령 단추의 표시된 텍스트를 표제 아래 상자 분류 된 탭을 클릭 한 다음 대화 상자를 닫습니다.

아래 스크린 샷과 같이 Command Button의 표시된 텍스트가 변경된 것을 볼 수 있습니다.

4. 명령 단추를 다시 마우스 오른쪽 단추로 클릭 한 다음 코드보기 오른쪽 클릭 메뉴에서.

5. 그런 다음 응용 프로그램 용 Microsoft Visual Basic 창에서 원래 코드를 아래 VBA 코드로 바꾸십시오. 암호 창.

VBA 코드 : 명령 단추로 빈 새 행 자동 삽입

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

주의 사항: 코드에서 CommanButton1은 생성 한 Command Button의 이름입니다.

6. 프레스 다른 + Q 키를 동시에 닫아 응용 프로그램 용 Microsoft Visual Basic 창문. 그리고 끄십시오 디자인 모드 아래 개발자 탭.

7. 삽입 된 명령 단추를 클릭하고 Excel 용 Kutools 대화 상자가 나타납니다. 빈 새 행을 추가 할 특정 행 번호를 입력 한 다음 OK 단추. 스크린 샷보기 :

그런 다음 아래 스크린 샷과 같이 빈 새 행이 워크 시트의 지정된 위치에 삽입됩니다. 그리고 위 셀의 셀 서식을 유지합니다.


관련 기사:

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
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