انتقل إلى المحتوى الرئيسي

كيفية إدراج صف تلقائيًا بناءً على قيمة الخلية في إكسيل؟

doc-insert-row-on-value-1
افترض أن لديك نطاقًا من البيانات ، وتريد إدراج صفوف فارغة تلقائيًا أعلى أو أسفل قيمة معينة في Excel ، على سبيل المثال ، صفوف الإدراج التلقائي تحت قيمة الصفر كما هو موضح أدناه لقطة الشاشة. في Excel ، لا توجد طريقة مباشرة لحل هذه المهمة ، ولكن يمكنني تقديم رمز ماكرو لك لإدراج الصفوف تلقائيًا بناءً على قيمة معينة في Excel.
قم بإدراج صف أدناه بناءً على قيمة الخلية باستخدام VBA

أدخل صفًا أعلاه بناءً على قيمة الخلية باستخدام Kutools for Excel فكرة جيدة 3

لإدراج صف بناءً على قيمة الخلية عن طريق تشغيل VBA ، يرجى القيام بالخطوات التالية:

1. صحافة ALT + F11 مفاتيح في وقت واحد ، و ميكروسوفت فيسوال باسيك للتطبيقات نافذة تخرج.

2. انقر إدراج > وحدة، ثم الصق رمز VBA أدناه إلى ظهرت وحدة نافذة.

فبا: إدراج صف أدناه بناءً على قيمة الخلية.

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. انقر F5 مفتاح أو يجري زر ، ينبثق مربع حوار ، وحدد العمود الذي يحتوي على صفر. انظر لقطة الشاشة:
doc-insert-row-on-value-2

4. انقر OK. ثم سيتم إدراج الصفوف الفارغة تحت قيمة الصفر.
doc-insert-row-on-value-3

معلومه- سرية:

1. إذا كنت تريد إدراج صفوف بناءً على قيمة أخرى ، فيمكنك التغيير 0 إلى أي قيمة تريدها في VBA: إذا كانت Rng.Value = "0" إذن.

2. إذا كنت تريد إدراج صفوف أعلى من الصفر أو أي قيمة أخرى ، فيمكنك استخدام كود vba أدناه.

فبا: إدراج صف أعلى قيمة الصفر:

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-insert-row-on-value-4


إذا لم تكن معتادًا على VBA ، فيمكنك المحاولة كوتولس ل إكسيل's حدد خلايا معينة فائدة ، ثم أدخل الصفوف أعلاه.

كوتولس ل إكسيل, مع أكثر من 300 وظائف يدوية ، تجعل مهامك أكثر سهولة. 

بعد تثبيت Kutools for Excel ، يرجى القيام بما يلي:(تنزيل مجاني Kutools for Excel الآن!)

1. حدد القائمة التي تريد معرفة الخلايا المحددة منها ، ثم انقر فوق كوتولس > أختار > حدد خلايا معينة. انظر لقطة الشاشة:
إدراج صف doc بناءً على القيمة 9

2. في مربع حوار الفرقعة ، تحقق الصف بأكمله الخيار ، ثم انتقل للتحديد يساوي تبدأ من نوع خاص أو معين القائمة ، ثم أدخل القيمة التي تريد البحث عنها في مربع النص الصحيح. انظر لقطة الشاشة:
إدراج صف doc بناءً على القيمة 6

3. انقر Ok، وينبثق مربع حوار لتذكيرك بعدد الصفوف المحددة ، ما عليك سوى إغلاقها.

4. ضع المؤشر على صف واحد محدد ، وانقر بزر الماوس الأيمن للتحديد إدراج من قائمة السياق. انظر لقطة الشاشة:
إدراج صف doc بناءً على القيمة 7

الآن يتم إدراج الصفوف أعلاه بناءً على قيمة محددة.
إدراج صف doc بناءً على القيمة 8


مقالات ذات صلة:

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
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