Ga naar hoofdinhoud

Hoe rij automatisch invoegen op basis van celwaarde in Excel?

doc-rij-invoegen-gebaseerd-op-waarde-1
Stel dat u een gegevensbereik heeft en u wilt automatisch lege rijen boven of onder een bepaalde waarde in Excel invoegen, bijvoorbeeld automatisch rijen onder nul invoegen, zoals onderstaand screenshot. In Excel is er geen directe manier om deze taak op te lossen, maar ik kan een macrocode introduceren waarmee u automatisch rijen kunt invoegen op basis van een bepaalde waarde in Excel.
Voeg onderstaande rij in op basis van de celwaarde met VBA

Rij hierboven invoegen op basis van de celwaarde met Kutools voor Excel goed idee 3

Voer de onderstaande stappen uit om een ​​rij in te voegen op basis van de celwaarde door VBA uit te voeren:

1. druk op Alt + F11 toetsen tegelijk, en a Microsoft Visual Basic voor toepassingen venster springt uit.

2. klikken Invoegen > Moduleen plak vervolgens onder VBA-code in de popping Module venster.

VBA: rij hieronder invoegen op basis van de celwaarde.

Sub BlankLine()
	'Updateby20150203
	Dim Rng As Range
	Dim WorkRng As Range
	On Error Resume Next
	xTitleId                   = "KutoolsforExcel"
	Set WorkRng                = Application.Selection
	Set WorkRng                = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
	Set WorkRng                = WorkRng.Columns(1)
	xLastRow                   = WorkRng.Rows.Count
	Application.ScreenUpdating = False
	For xRowIndex = xLastRow To 1 Step - 1
		Set Rng                   = WorkRng.Range("A" & xRowIndex)
		If Rng.Value = "0" Then
			Rng.Offset(1, 0).EntireRow.Insert Shift: = xlDown
		End If
	Next
	Application.ScreenUpdating = True
End Sub

3. klikken F5 sleutel of de lopen knop, verschijnt er een dialoogvenster en selecteert u dat de kolom nul bevat. Zie screenshot:
doc-rij-invoegen-gebaseerd-op-waarde-2

4. klikken OK. Vervolgens worden lege rijen ingevoegd onder de nulwaarde.
doc-rij-invoegen-gebaseerd-op-waarde-3

Tip:

1. Als u rijen wilt invoegen op basis van een andere waarde, kunt u dit wijzigen 0 naar elke gewenste waarde in de VBA: Als Rng.Value = "0" Dan.

2. Als u rijen boven nul of een andere waarde wilt invoegen, kunt u de onderstaande vba-code gebruiken.

VBA: rij boven nulwaarde invoegen:

Sub BlankLine()
	'Updateby20150203
	Dim Rng As Range
	Dim WorkRng As Range
	On Error Resume Next
	xTitleId                   = "KutoolsforExcel"
	Set WorkRng                = Application.Selection
	Set WorkRng                = Application.InputBox("Range", xTitleId, WorkRng.Address, Type: = 8)
	Set WorkRng                = WorkRng.Columns(1)
	xLastRow                   = WorkRng.Rows.Count
	Application.ScreenUpdating = False
	For xRowIndex = xLastRow To 1 Step - 1
		Set Rng                   = WorkRng.Range("A" & xRowIndex)
		If Rng.Value = "0" Then
			Rng.EntireRow.Insert Shift: = xlDown
		End If
	Next
	Application.ScreenUpdating = True
End Sub

doc-rij-invoegen-gebaseerd-op-waarde-4


Als u niet bekend bent met VBA, kunt u het proberen Kutools for Excel's Selecteer specifieke cellen hulpprogramma en voeg vervolgens rijen hierboven in.

Kutools for Excel, met meer dan 300 handige functies, maakt uw werk eenvoudiger. 

Na het installeren van Kutools voor Excel, doe het als volgt:(Download nu Kutools voor Excel!)

1. Selecteer de lijst waaruit u de specifieke cellen wilt weten, en klik op Kutools > kies > Selecteer specifieke cellen. Zie screenshot:
doc rij invoegen op basis van waarde 9

2. Vink in het popping-dialoogvenster aan Hele rij optie, en ga dan om te selecteren Is gelijk aan oppompen van Specifiek type lijst, en typ vervolgens de waarde die u wilt zoeken in het rechter tekstvak. Zie screenshot:
doc rij invoegen op basis van waarde 6

3. klikken Ok, en er verschijnt een dialoogvenster om u aan het aantal geselecteerde rijen te herinneren, sluit het gewoon.

4. Plaats de cursor op een geselecteerde rij en klik met de rechtermuisknop om te selecteren Invoegen vanuit het contextmenu. Zie screenshot:
doc rij invoegen op basis van waarde 7

Nu worden de rijen hierboven ingevoegd op basis van een specifieke waarde.
doc rij invoegen op basis van waarde 8


Relatieve artikelen:

Beste Office-productiviteitstools

🤖 Kutools AI-assistent: Een revolutie teweegbrengen in de data-analyse op basis van: Intelligente uitvoering   |  Genereer code  |  Aangepaste formules maken  |  Analyseer gegevens en genereer grafieken  |  Roep Kutools-functies aan...
Populaire functies: Zoek, markeer of identificeer duplicaten   |  Verwijder lege rijen   |  Combineer kolommen of cellen zonder gegevens te verliezen   |   Ronde zonder formule ...
Super opzoeken: Meerdere criteria VLookup    VLookup met meerdere waarden  |   VOpzoeken over meerdere bladen   |   Fuzzy opzoeken ....
Geavanceerde vervolgkeuzelijst: Maak snel een vervolgkeuzelijst   |  Afhankelijke vervolgkeuzelijst   |  Multi-select vervolgkeuzelijst ....
Kolom Beheerder: Voeg een specifiek aantal kolommen toe  |  Kolommen verplaatsen  |  Schakel de zichtbaarheidsstatus van verborgen kolommen in  |  Vergelijk bereiken en kolommen ...
Uitgelichte functies: Raster focus   |  Ontwerpweergave   |   Grote formulebalk    Werkmap- en bladbeheer   |  resource Library (Auto-tekst)   |  Datumkiezer   |  Combineer werkbladen   |  Cellen coderen/decoderen    Stuur e-mails per lijst   |  Super filter   |   Speciaal filter (filter vet/cursief/doorhalen...) ...
Top 15 gereedschapsets12 Tekst Tools (toe te voegen tekst, Tekens verwijderen, ...)   |   50+ tabel Types (Gantt Chart, ...)   |   40+ Praktisch Formules (Bereken leeftijd op basis van verjaardag, ...)   |   19 Invoeging Tools (QR-code invoegen, Afbeelding invoegen vanaf pad, ...)   |   12 Camper ombouw Tools (Getallen naar woorden, Currency Conversion, ...)   |   7 Samenvoegen en splitsen Tools (Geavanceerd Combineer rijen, Gespleten cellen, ...)   |   ... en meer

Geef uw Excel-vaardigheden een boost met Kutools voor Excel en ervaar efficiëntie als nooit tevoren. Kutools voor Excel biedt meer dan 300 geavanceerde functies om de productiviteit te verhogen en tijd te besparen.  Klik hier om de functie te krijgen die u het meest nodig heeft...

Omschrijving


Office-tabblad Brengt een interface met tabbladen naar Office en maakt uw werk veel gemakkelijker

  • Schakel bewerken en lezen met tabbladen in Word, Excel, PowerPoint in, Publisher, Access, Visio en Project.
  • Open en maak meerdere documenten in nieuwe tabbladen van hetzelfde venster in plaats van in nieuwe vensters.
  • Verhoogt uw productiviteit met 50% en vermindert honderden muisklikken voor u elke dag!
Comments (43)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hola mira necesito agregar filas en blanco automaticamente cuando se me produce desbordamiento en diferentes filas y probe varias formas y no lo toma.
me podrias ayudar?desde ya gracias
This comment was minimized by the moderator on the site
need help with a code. I am trying insert rows based on value in another cell on another worksheet (same workbook). then automatically update that number if blank cell if filled. so basically worksheet 1 has, column A all time starts from 4 am to 10 pm. Column B is employee name. Worksheet 2 has time starts in column A and available shifts for that time start in column B. I need to find a way to automatically insert blank row at last time start ie 4 am in worksheet 1 if worksheet 2 has ie. 1 available shift to pick up for 4 am. then update the number in worksheet 2 if the cell if fill at a later time. Is this possible?
This comment was minimized by the moderator on the site
Gracias por tu macro, he utilizado la primera y me funciona perfectamente.
Necesitaría a la vez de generar una fila en blanco debajo de otra dependiendo de un valor, que esa linea se copie en la que se ha generado en blanco.
Me seria de gran ayuda.
This comment was minimized by the moderator on the site
Can anyone suggest how to do this with adding 1 row for any number grater than 0?
This comment was minimized by the moderator on the site
Hi, Jordan, change the script: If Rng.Value = "0" Then to If Rng.Value > "0" Then
in the vba of the article.
This comment was minimized by the moderator on the site
Instead of a dialogue box that pops up asking which cells it should look at, how can I instead just require a preset range? In this case I want it to always run it for E3 to E800. Thanks!
This comment was minimized by the moderator on the site
Hi, Christopher M, try below code, it take A1:A10 as an example, just change it as you need.
Sub BlankLine()
'ByExtendoffice
Dim Rng As Range

Dim WorkRng As Range

Dim xRngI As Range

On Error Resume Next

xTitleId = "KutoolsforExcel"

Set WorkRng = Application.Range("A1:A10") 'Change the range as you need

Set WorkRng = WorkRng.Columns(1)

xLastRow = WorkRng.Rows.Count

Application.ScreenUpdating = False

For xRowIndex = xLastRow To 1 Step -1

  Set Rng = WorkRng.Range("A" & xRowIndex)

  If Rng.Value = "Node1" Then

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).Value = "Scanner"

    Rng.Offset(2, 0).Value = "Printer"

    Rng.Offset(3, 0).Value = "CD"

  End If

Next

Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
I need to add particular rows with values in them for specific cell contents, but not sure how to do so without having to manually do for over 3800+ lines

Ex: A1 = Node1
I need to have a row inserted and it to enter the value Scanner
Enter another row and enter the value Printer
another row with value CD.
Etc
This comment was minimized by the moderator on the site
Hi, Chris, here is a VBA can help you to automatically insert three rows (Scanner, Printer, CD) when the value equal to Node1.
Sub BlankLine()
'ByExtendoffice
Dim Rng As Range

Dim WorkRng As Range

Dim xRngI As Range

On Error Resume Next

xTitleId = "KutoolsforExcel"

Set WorkRng = Application.Selection

Set WorkRng = Application.InputBox("Select a range", xTitleId, WorkRng.Address, Type:=8)

Set WorkRng = WorkRng.Columns(1)

xLastRow = WorkRng.Rows.Count

Application.ScreenUpdating = False

For xRowIndex = xLastRow To 1 Step -1

  Set Rng = WorkRng.Range("A" & xRowIndex)

  If Rng.Value = "Node1" Then

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).EntireRow.Insert Shift:=xlDown

    Rng.Offset(1, 0).Value = "Scanner"

    Rng.Offset(2, 0).Value = "Printer"

    Rng.Offset(3, 0).Value = "CD"

  End If

Next

Application.ScreenUpdating = True

End Sub

Please let me know if works for you.
This comment was minimized by the moderator on the site
Hi,
Can this marco be used/altered for colored cells?
I need to insert at least 10 rows above end of the each series which are colored.
Thx!
This comment was minimized by the moderator on the site
please help mei have a data.i have one month time data, in that i have to insert a empty rows according to the escape time
This comment was minimized by the moderator on the site
Hi, hr.babu08, sorry the reply is late. I guess you want to insert blank rows or make a mark for the missing sequence data, if so, you can try Kutools for Excel's Find Missing Sequence Number feature.Here is the tutorial about the feature: https://www.extendoffice.com/product/kutools-for-excel/excel-find-missing-numbers-in-sequence.htmlIf you want other methods on inserting blank rows for missing sequence, please visit:https://www.extendoffice.com/documents/excel/3522-excel-find-missing-dates.html</div>;
This comment was minimized by the moderator on the site
Hello. The macro works for me but is there a way to always have the range/parameters set always to column J without the input box coming up at all? I would like it to skip the step of the input box coming up. Also, I have made sure that directly before this macro that the last line of my previous macro is Range("J:J").Select to make sure the whole J column is already selected.
This is what I have been using so far.

Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Click OK to Continue"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Set WorkRng = WorkRng.Columns(1)
SendKeys "~"
xLastRow = WorkRng.Rows.Count
Application.ScreenUpdating = False
For xRowIndex = xLastRow To 1 Step -1
Set Rng = WorkRng.Range("A" & xRowIndex)
If Rng.Value = "New GMS Line" Then
Rng.EntireRow.Insert Shift:=xlDown
End If
Next


I Have tried experimenting using the SendKeys "~" command between some of the steps to try and get it to press enter automatically when the input box comes up but that hasn't worked either. I wasn't sure where exactly to use the SendKeys command in the macro or if it would even work with an input box!
This comment was minimized by the moderator on the site
Many thanks for this, really a tremendous time saver. Would it be possible to add some code which allows me to insert some text in the new row. For example i'm inserting new rows based on target value 'x', then i want to add text value 'y' in the cell below target value 'x'. Is this possible?
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