Excel File Become Slower when using VBA code.

Man_of_Sleep

New Member
Joined
Aug 5, 2020
Messages
19
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I would to introduce myself, I am a data entry clerk with zero knowledge on VBA.
I am using with excel 2013, after discover this forum, many thing I get to improve my excel file.
Thanks to all members here.

My excel flow is like this:
1) User insert data in column B until Z by row, after finish, then using drop-down list at column AA select YES to locked the entire row.
Problem when I use the VBA (protect the entire row when select YES in AA):
1) User can't autofilter, I already spent 3 days browsing this forum to try to solved, but failed.
2) User can't use add a row with a check box reference to a specific cell in column A (this is done by macro).
3) User can't use the expand/hide grouping column.
4) user can't edit range in column G and H, after the entire row is protected.
5) is there any simplified VBA to make my excel run more faster?

Please teach me how to solve above problem.

Thank you very much in advance for your help.

Capture.JPG



Below is my code:

VBA Code:
Sub addNewRow_r2()
    ' Do not insert a row before the first row.
    Const TopRow As Long = 1
    
    ' Get the active row number.
    Dim rowNum As Long
    rowNum = ActiveCell.Row
    
    If (rowNum > TopRow) Then

        Rows(rowNum).Insert       ' Insert a new row.
        
        ' === add a Check Box ===
        Dim oCB As CheckBox
        Dim c   As Range
        
        Set c = Cells(rowNum, 1)
        With c
            Set oCB = CheckBoxes.Add(.Left, .Top, .Width, .Height)
            oCB.LinkedCell = .Address
            oCB.Caption = vbNullString
        End With
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cell In Range("AA10:AA110")

If cell.Value = "YES" Then

ActiveSheet.Unprotect "Password"

cell.EntireRow.Locked = True

ActiveSheet.Protect "Password"

End If

Next cell

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi

I note that you protect the sheet to not allow your locked cells to be edited however by default when protecting the sheet Insert new row is not allowed, however if you check the option in the protect sheet dialogue you will then retain the ability to insert rows. It would look like this in the code.

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowInsertingRows:=True

Hope that helps
 

Attachments

  • Screenshot 2023-01-20 101703.png
    Screenshot 2023-01-20 101703.png
    13.6 KB · Views: 8
Upvote 0
Similarly, you can use
VBA Code:
ActiveSheet.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowInsertingRows:=True, allowfiltering:=true
to allow the autofilter.

Adding Allowformattingcells:=true MIGHT allow you to group as well, but I haven't tested it.

 
Upvote 0
I am sorry, I already spent hours of trying to add the code.
But error.

Can you show where to copy & paste the code inside my current code?
 
Upvote 0
sorry, only this code to allow the group/ungroup is not possible when in protected mode.

Allowformattingcells:=true

Is there any solution?
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top