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

كيف تحافظ على الجدول قابل للتوسيع عن طريق إدراج صف الجدول في ورقة عمل محمية في إكسيل؟

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

احتفظ بالجدول قابلاً للتوسيع عن طريق إدراج صف جدول في ورقة عمل محمية برمز VBA


احتفظ بالجدول قابلاً للتوسيع عن طريق إدراج صف جدول في ورقة عمل محمية برمز VBA

كما هو موضح أدناه ، يوجد جدول يسمى Table1 في ورقة العمل الخاصة بك ، والعمود الأخير من الجدول هو عمود الصيغة. أنت الآن بحاجة إلى حماية ورقة العمل لمنع تغيير عمود الصيغة ، مع السماح بتوسيع الجدول عن طريق إدراج صف جديد وتعيين بيانات جديدة في الخلايا الجديدة. الرجاء القيام بما يلي.

1. انقر المطور > إدراج > زر (التحكم في النموذج) لإدراج أ التحكم بالنموذج زر في ورقة العمل الخاصة بك.

2. في ظهرت تعيين ماكرو مربع الحوار، انقر فوق جديد .

3. في ال ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، يرجى نسخ ولصق رمز VBA أدناه بين ملف فرعية و نهاية الفرعية الفقرات في رمز نافذة.

كود فبا: حافظ على الجدول قابل للتوسيع عن طريق إدراج صف الجدول في ورقة عمل محمية

 'Update by ExtendOffice 20220826
    Dim xRg, tableRg As Range
    Dim xRowCount As Integer
    Dim pswStr As String
    pswStr = "123"
    On Error Resume Next
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:=pswStr

    Set tableRg = ActiveSheet.ListObjects("Table4").Range
    xRowCount = tableRg.Rows.Count
    
    Set xRg = Range("Table4[[#Headers],[Total]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault

    ActiveSheet.Protect Password:=pswStr, DrawingObjects:=False, _
                    Contents:=True, Scenarios:=False, _
                    AllowFormattingCells:=True, AllowFormattingColumns:=True, _
                    AllowFormattingRows:=True, AllowInsertingColumns:=True, _
                    AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
                    AllowDeletingColumns:=True, AllowDeletingRows:=True, _
                    AllowSorting:=True, AllowFiltering:=True, _
                    AllowUsingPivotTables:=True
    Application.ScreenUpdating = True

ملاحظة:

1). في الكود ، الرقم "123" هو كلمة المرور التي ستستخدمها لحماية ورقة العمل.
2). الرجاء تغيير اسم الجدول واسم العمود الذي يحتوي على الصيغة التي ستحميها.

4. اضغط على قديم + Q مفاتيح لإغلاق نافذة ميكروسوفت فيسوال باسيك للتطبيقات.

5. حدد الخلايا في الجدول التي تريد تعيين بيانات جديدة إليها باستثناء عمود الصيغة ، ثم اضغط على CTRL + 1 مفاتيح لفتح تنسيق الخلايا صندوق المحادثة. في ال تنسيق الخلايا مربع الحوار ، قم بإلغاء تحديد مقفل مربع ، ثم انقر فوق OK زر. انظر لقطة الشاشة:

6. الآن قم بحماية ورقة العمل الخاصة بك بكلمة المرور التي حددتها في رمز VBA.

من الآن فصاعدًا ، بعد النقر فوق الزر "التحكم في النموذج" في ورقة العمل المحمية ، سيكون الجدول قابلاً للتوسيع عن طريق إدراج صف جديد كما هو موضح أدناه.

ملاحظات: يمكنك تعديل الجدول باستثناء عمود الصيغة في ورقة العمل المحمية.


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

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

🤖 مساعد 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 (19)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
hello, I've copied and pasted the code into VBA, amended the table name and selected the columns I want to protect. I click the button however all it does is protects the sheet but not add any new table rows. Any advice?
This comment was minimized by the moderator on the site
Sub ButtonOut_Click()

Dim PswS As String
PswStr = "54321"

On Error Resume Next

Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=PswStr

ActiveSheet.ListObjects("Table1").ListRows.Add

ActiveSheet.Protect Password:=PswStr
Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
The code is not working.
Several errors.

Dim xRg, tableRg As Range

xRg
is a variant not a range

yRg
not declared at all

Set xRg = Range("Table4[[#Headers],[Total]]").Offset(1, 0)

runtime error 1004
When I take away the TOTAL, it works.
It is not working with the total row displayed and neither when I hide the total row in the ribbon.

Normally your website is really great, but this article need improvment.
This comment was minimized by the moderator on the site
Hi prem,
You need to make sure that the table name and column header specified in the code match the table name and column header in the worksheet. To avoid the 1004 error, you may need to enable the trust access to the VBA project object model in your Excel: click File > Options > Trust Center > Trust Center Settings > Macro Settings > and then check the Trust access to the VBA project object model box.
This comment was minimized by the moderator on the site
Hi.

Thanks for sharing. Though I have a question... by using the code above, I can add one row at a time. How to add multiple rows in one click?

Thanks in advance.

'Update by ExtendOffice 20220826
Dim xRg, tableRg As Range
Dim xRowCount As Integer
Dim pswStr As String
pswStr = "123"
On Error Resume Next
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=pswStr

Set tableRg = ActiveSheet.ListObjects("Table4").Range
xRowCount = tableRg.Rows.Count

Set xRg = Range("Table4[[#Headers],[Total]]").Offset(1, 0)
Set yRg = xRg.Resize(xRowCount, 1)
xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault

ActiveSheet.Protect Password:=pswStr, DrawingObjects:=False, _
Contents:=True, Scenarios:=False, _
AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, _
AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, AllowDeletingRows:=True, _
AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
Application.ScreenUpdating = True
This comment was minimized by the moderator on the site
Hola!!!
Tengo una tabla donde más de una columna está protegida.
La tabla tiene 17 columnas de las cuales 7 deben quedar bloqueadas porque poseen fórmulas.
Mi tabla arranca en celda A4

Estaba tratando de usar este código para probarlo, cambiando lo que verán abajo como "CLAVE", "MITABLA" y "AVISO 1" por mis nombres particulares:
Donde "AVISO 1" corresponde a una de las columnas que está protegida.

Dim pswStr As String
'Update by ExtendOffice 20181106
pswStr = "CLAVE"
On Error Resume Next
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=pswStr
ActiveSheet.Range("A4").Select
Range("MITABLA[[#Headers],[AVISO 1]]").Select
Selection.End(xlDown).Select
Selection.Offset(1, -16).Select
ActiveCell.FormulaR1C1 = "new"
ActiveSheet.Protect Password:=pswStr, DrawingObjects:=False, _
Contents:=True, Scenarios:=False, _
AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, _
AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
AllowDeletingColumns:=True, AllowDeletingRows:=True, _
AllowSorting:=True, AllowFiltering:=True, _
AllowUsingPivotTables:=True
Selection.ClearContents
Application.ScreenUpdating = True

Lo que está haciendo el código tal cual como lo escribo es que en lugar de agregar una nueva línea a mi tabla, está colocando la palabra "new" en la última celda con contenido de la columna "AVISO 1".

Surgen entonces 2 dudas:
1. ¿cómo podría hacer para determinar más de una columna protegida?
2. ¿por qué está haciendo esto el código definido?

Agradezco de antemano que me puedan ayudar! Estaré atenta.
This comment was minimized by the moderator on the site
Hi Daina,
1. If the 7 formula columns that you want to protect are consecutive in the table.
For example, the headers of the columns are gg, hh, ii, jj, kk, ll, mm as shown in the screenshot below. You can apply the following VBA code to get it done.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/table.png
In this line Set xRg = Range("Table3[[#Headers],[gg]:[mm]]").Offset(1, 0) in the following code, you just need to enter the headers of the first column and the last column.
Sub Button1_Click()
 'Update by ExtendOffice 20220826
    Dim xRg, tableRg As Range
    Dim xRowCount As Integer
    Dim pswStr As String
    pswStr = "123"
    On Error Resume Next
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:=pswStr

    'Change the table name and the column headers
    Set tableRg = ActiveSheet.ListObjects("Table3").Range
    xRowCount = tableRg.Rows.Count
    
     Set xRg = Range("Table3[[#Headers],[gg]:[mm]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, xRg.Columns.Count)

    xRg.Resize(xRowCount - 1, xRg.Columns.Count).AutoFill Destination:=yRg, Type:=xlFillDefault
    

    ActiveSheet.Protect Password:=pswStr, DrawingObjects:=False, _
                    Contents:=True, Scenarios:=False, _
                    AllowFormattingCells:=True, AllowFormattingColumns:=True, _
                    AllowFormattingRows:=True, AllowInsertingColumns:=True, _
                    AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
                    AllowDeletingColumns:=True, AllowDeletingRows:=True, _
                    AllowSorting:=True, AllowFiltering:=True, _
                    AllowUsingPivotTables:=True
    Application.ScreenUpdating = True
End Sub

2. If the 7 formula columns that you want to protect are discontinuous in the table. Apply the following code. In the code, you need to manually input the headers of the columns one by one.
Sub Button1_Click()
 'Update by ExtendOffice 20220826
    Dim xRg, tableRg As Range
    Dim xRowCount As Integer
    Dim pswStr As String
    pswStr = "123"
    On Error Resume Next
    Application.ScreenUpdating = False
    ActiveSheet.Unprotect Password:=pswStr

    'Change the table name and the column headers
    Set tableRg = ActiveSheet.ListObjects("Table3").Range
    xRowCount = tableRg.Rows.Count
    
    Set xRg = Range("Table3[[#Headers],[gg]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
    Set xRg = Range("Table3[[#Headers],[hh]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
    Set xRg = Range("Table3[[#Headers],[ii]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
    Set xRg = Range("Table3[[#Headers],[jj]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
    Set xRg = Range("Table3[[#Headers],[kk]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
     Set xRg = Range("Table3[[#Headers],[ll]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault
    Set xRg = Range("Table3[[#Headers],[mm]]").Offset(1, 0)
    Set yRg = xRg.Resize(xRowCount, 1)
    xRg.Resize(xRowCount - 1, 1).AutoFill Destination:=yRg, Type:=xlFillDefault

    ActiveSheet.Protect Password:=pswStr, DrawingObjects:=False, _
                    Contents:=True, Scenarios:=False, _
                    AllowFormattingCells:=True, AllowFormattingColumns:=True, _
                    AllowFormattingRows:=True, AllowInsertingColumns:=True, _
                    AllowInsertingRows:=True, AllowInsertingHyperlinks:=True, _
                    AllowDeletingColumns:=True, AllowDeletingRows:=True, _
                    AllowSorting:=True, AllowFiltering:=True, _
                    AllowUsingPivotTables:=True
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
How do I create a button to erase lines?
This comment was minimized by the moderator on the site
Merhaba Tablo ismini ve satır başlangıc yerlerini değiştirdiğim zaman kod çalışmıyor yardımcı olurmusunuz
This comment was minimized by the moderator on the site
Hi,
Make sure you have changed to the exact same table name and column header in the code.
I have changed the table name and the column header to test the code, and it works well.
Did you get any error prompt? I need to know more specific about your issue, such as your Excel version. The more detailed you describe the error, the faster we can understand and solve it.
This comment was minimized by the moderator on the site
Hello,

the code worked initially, but after I duplicated the worksheet, it stayed for after 24 hours then all the code disappeared. And now I can’t access the worksheet.

it keeps telling me incorrect password. And the code have disappeared. .
This comment was minimized by the moderator on the site
Hello, I used the above code and got the following error message:
"Code execution has been interrupted". When I click on Debug, Line 20 "Selection.ClearContents" is highlighted.

When I initially entered the code, it worked correctly.

I changed "Table" to the name of the table and change the column to the name of the column I am using. I also changed the "Selection.Offset (x,-x).Select" to match my needs.


Any suggestions as to why this is occurring?
This comment was minimized by the moderator on the site
Try this Vba code for add new line in you table

Sub Tab_Line_Add()
Dim pswStr As String
pswStr = "123"
On Error Resume Next
Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:=pswStr
ActiveSheet.Range("D8").Select
'D8 is tabel header
Range("Table1[[#Headers],[Total]]").Select
Selection.End(xlDown).Select
Selection.ListObject.ListRows.Add AlwaysInsert:=False
ActiveSheet.Protect Password:=pswStr

End Sub
.
This comment was minimized by the moderator on the site
using the suggested (Selection.ListObject.ListRows.Add AlwaysInsert:=False) fixed a similar problem for me with the original code, where a new full row (extending down cell contained formulas) would not be added to the table on a much wider table 51 columns. So thanks for sharing and fixing Mac.
This comment was minimized by the moderator on the site
Hi Mac,
Thanks for sharing.
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