Բաց թողնել հիմնական բովանդակությունը

Ինչպե՞ս պաշտպանել բջիջները ՝ ելնելով Excel- ի ամսաթվից:

Սովորաբար, մենք կարող ենք պաշտպանել աշխատաթերթը ՝ կանխելու համար, որ մյուսները բջիջների արժեքները խմբագրեն կամ փոփոխեն, բայց, երբեմն, անհրաժեշտ է պաշտպանել բջիջները ՝ ելնելով ամսաթվից: Օրինակ ՝ ես ուզում եմ պաշտպանել այլ բջիջներ, բայց թույլ եմ տալիս միայն այսօրվա ամսաթվի բջիջների արժեքները փոփոխել, ինչպես ցույց է տրված հետևյալ նկարում, այս հոդվածում կխոսվի, թե ինչպես պաշտպանել բջիջները ՝ ելնելով ամսաթվից:

doc պաշտպանել ըստ ամսաթվի 1

Պաշտպանեք բոլոր տողերը, բացի այսօրվա ամսաթվից VBA կոդով

Պաշտպանեք բոլոր տողերը, որոնց ամսաթիվն անցել է, VBA կոդով


նետ կապույտ աջ պղպջակ Պաշտպանեք բոլոր տողերը, բացի այսօրվա ամսաթվից VBA կոդով

Թույլ տվեք փոփոխել միայն այսօրվա ամսաթվին հավասար տողը, հետևյալ ծածկագիրը կարող է օգնել ձեզ, խնդրում ենք արեք հետևյալ կերպ.

1, Աջ կտտացրեք այն թերթիկի ներդիրին, որը ցանկանում եք պաշտպանել բջիջները ՝ ելնելով ամսաթվից, և այնուհետև ընտրել Դիտել կոդը համատեքստի ընտրացանկից ՝ դուրս եկած պատուհանում Microsoft Visual Basic հավելվածների համար պատուհանը, խնդրում ենք պատճենել և տեղադրեք հետևյալ կոդը դատարկ Մոդուլի մեջ.

VBA կոդ. Պաշտպանեք բոլոր տողերը, բացառությամբ այսօրվա ամսաթվերի:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice 20161025
    If Range("E" & Selection.Row).Value <> Date Then
        ActiveSheet.Protect Password:="111111"
        MsgBox "Only today's date row can be edited!", vbInformation, "Kutools for Excel"
    ElseIf Range("E" & Selection.Row).Value = Date Then
        ActiveSheet.Unprotect Password:="111111"
        ActiveSheet.EnableSelection = xlNoRestrictions
    End If
End Sub

doc պաշտպանել ըստ ամսաթվի 2

ՆշումՎերոհիշյալ ծածկագրում `նամակը E սյունակի վերնագիրն է, որտեղ տեղակայված է ամսաթիվը, «111111”Այս ծածկագիրը պաշտպանելու գաղտնաբառն է: Կարող եք դրանք փոխել ըստ ձեր կարիքի:

2, Դրանից հետո պահեք և փակեք այս կոդի պատուհանը:

(1.) Եթե դուք կտտացնում եք այլ բջիջներ այսօրվա ամսաթվից այն կողմ, ապա հուշում է արկղը ՝ հիշեցնելու համար, որ բջիջը հնարավոր չէ խմբագրել, տես նկարի նկարը.

doc պաշտպանել ըստ ամսաթվի 3

(2.) Եթե կտտացրեք և խմբագրեք տողը հավասար է այսօրվա ամսաթվին, այն հաջողությամբ կփոփոխվի, տես նկարի նկարը.

doc պաշտպանել ըստ ամսաթվի 4


նետ կապույտ աջ պղպջակ Պաշտպանեք բոլոր տողերը, որոնց ամսաթիվն անցել է, VBA կոդով

Եթե ​​Ձեզ անհրաժեշտ է պաշտպանել բոլոր տողերը, երբ անցել է ամսաթիվը, թույլ տվեք փոփոխել միայն այսօրվա և ապագա ամսաթվերի շարքերը, կիրառեք հետևյալ VBA կոդը.

1, Աջ կտտացրեք այն թերթիկի ներդիրին, որը ցանկանում եք պաշտպանել բջիջները ՝ ելնելով ամսաթվից, և այնուհետև ընտրել Դիտել կոդը համատեքստի ընտրացանկից ՝ դուրս եկած պատուհանում Microsoft Visual Basic հավելվածների համար պատուհանը, խնդրում ենք պատճենել և տեղադրեք հետևյալ կոդը դատարկ Մոդուլի մեջ.

VBA կոդ. Պաշտպանեք բոլոր շարքերի ամսաթիվը, որն անցել է.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updateby Extendoffice 20161025
  Dim xRow As Long
  xRow = 2
  ThisWorkbook.ActiveSheet.Unprotect Password:="111111"
  ThisWorkbook.ActiveSheet.Cells.Locked = False
  Do Until IsEmpty(Cells(xRow, 5))
    If Cells(xRow, 5) < Date Then
      Rows(xRow).Locked = True
    End If
    xRow = xRow + 1
  Loop
  ThisWorkbook.ActiveSheet.Protect Password:="111111"
End Sub

doc պաշտպանել ըստ ամսաթվի 5

ՆշումՎերոհիշյալ կոդում համարը 5 սյունակի համարն է, որտեղ տեղակայված է ամսաթիվը, «111111”Այս ծածկագիրը պաշտպանելու գաղտնաբառն է: Կարող եք դրանք փոխել ըստ ձեր կարիքի:

3, Դրանից հետո պահեք և փակեք այս կոդի պատուհանը:

(1.) Եթե կտտացնում եք բջիջների ամսաթվի անցման մասին, հուշում է արկղը, որը կհիշեցնի ձեզ, որ բջիջը հնարավոր չէ խմբագրել, տե՛ս նկարը.

doc պաշտպանել ըստ ամսաթվի 6

(2.) Եթե կտտացնում եք շարքերի բջիջը ՝ փորձելու համար փոխել արժեքները այսօրվա կամ ապագա ամսաթվով, այն հաջողությամբ կփոփոխվի, տես նկարի նկարը.

doc պաշտպանել ըստ ամսաթվի 7

Գրասենյակի արտադրողականության լավագույն գործիքները

🤖 Kutools AI օգնականՀեղափոխություն կատարել տվյալների վերլուծության հիման վրա՝ Խելացի կատարում   |  Ստեղծեք ծածկագիր  |  Ստեղծեք հատուկ բանաձևեր  |  Վերլուծել տվյալները և ստեղծել գծապատկերներ  |  Invoke Kutools-ի գործառույթները...
Հանրաճանաչ հատկություններ: Գտեք, ընդգծեք կամ նույնականացրեք կրկնօրինակները   |  Deleteնջել դատարկ շարքերը   |  Միավորել սյունակները կամ բջիջները՝ առանց տվյալների կորստի   |   Կլոր առանց բանաձևի ...
Super Փնտրել: Բազմաթիվ չափանիշների VLookup    Բազմակի արժեք VLookup  |   VLookup բազմաթիվ թերթերում   |   Fuzzy Փնտրել ....
Ընդլայնված բացվող ցուցակ: Արագ ստեղծեք բացվող ցուցակը   |  Կախված բացվող ցուցակ   |  Բազմակի ընտրություն Drop Down ցուցակ ....
Սյունակի կառավարիչ: Ավելացրեք որոշակի քանակությամբ սյունակներ  |  Տեղափոխել սյունակները  |  Փոխարկել թաքնված սյունակների տեսանելիության կարգավիճակը  |  Համեմատեք միջակայքերը և սյունակները ...
Առանձնահատկություններ: Ցանցի կենտրոնացում   |  Դիզայնի տեսք   |   Մեծ Formula Bar    Աշխատանքային գրքույկի և թերթիկների կառավարիչ   |  Ռեսուրսների գրադարան (Ավտոմատ տեքստ)   |  Ամսաթիվ ընտրող   |  Միավորել աշխատանքային թերթերը   |  Գաղտնագրել/գաղտնազերծել բջիջները    Ուղարկեք նամակներ ըստ ցանկի   |  Սուպեր զտիչ   |   Հատուկ զտիչ (զտել թավ/շեղ/շեղված...) ...
Լավագույն 15 գործիքների հավաքածու12 Տեքստ Գործիքներ (Ավելացրեք տեքստ, Հեռացնել նիշերը, ...)   |   50+ Աղյուսակ Տեսակներ (Գանտի աղյուսակը, ...)   |   40+ Գործնական Բանաձեւեր (Հաշվարկել տարիքը ՝ ելնելով ծննդյան տարեդարձից, ...)   |   19 միացում Գործիքներ (Տեղադրեք QR կոդ, Տեղադրեք նկար ուղուց, ...)   |   12 Փոխարկում Գործիքներ (Բառեր համարներ, Արտարժույթի փոխակերպումը, ...)   |   7 Միաձուլում և պառակտում Գործիքներ (Ընդլայնված կոմբինատ տողեր, Պառակտված բջիջներ, ...)   |   ... եւ ավելին

Լրացրեք ձեր Excel-ի հմտությունները Kutools-ի հետ Excel-ի համար և փորձեք արդյունավետությունը, ինչպես երբեք: Kutools-ը Excel-ի համար առաջարկում է ավելի քան 300 առաջադեմ առանձնահատկություններ՝ արտադրողականությունը բարձրացնելու և ժամանակ խնայելու համար:  Սեղմեք այստեղ՝ Ձեզ ամենաշատ անհրաժեշտ հատկանիշը ստանալու համար...

Նկարագրություն


Office Tab- ը Tabbed ինտերֆեյսը բերում է Office, և ձեր աշխատանքը շատ ավելի դյուրին դարձրեք

  • Միացնել ներդիրներով խմբագրումը և ընթերցումը Word, Excel, PowerPoint- ով, Հրատարակիչ, Access, Visio և Project:
  • Բացեք և ստեղծեք բազմաթիվ փաստաթղթեր նույն պատուհանի նոր ներդիրներում, այլ ոչ թե նոր պատուհաններում:
  • Բարձրացնում է ձեր արտադրողականությունը 50%-ով և նվազեցնում մկնիկի հարյուրավոր սեղմումները ձեզ համար ամեն օր:
Comments (30)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello, I would like to protect future days and allow editing current and past days. How do I do that?
This comment was minimized by the moderator on the site
Hello, Miguel,To protect the future days, please apply the below code:<div data-tag="code">Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updateby Extendoffice
Dim xRow As Long
xRow = 2
ThisWorkbook.ActiveSheet.Unprotect Password:="111111"
ThisWorkbook.ActiveSheet.Cells.Locked = False
Do Until IsEmpty(Cells(xRow, 5))
If Cells(xRow, 5) > Date Then
Rows(xRow).Locked = True
End If
xRow = xRow + 1
Loop
ThisWorkbook.ActiveSheet.Protect Password:="111111"
End SubPlease try, hope it can help you!
This comment was minimized by the moderator on the site
hello i did it but when i press cell message shows that it can not be edited but when i press keyborad i still can write in the cell
This comment was minimized by the moderator on the site
Hello, I tried to do the same but to Protect all columns except today’s date column with VBA code by replacing "Selection.Row" with "Selection.Columns" and "E" with "5" (row number where dates are), but I keep receiving error 1004!

Any help please?

Thank you
This comment was minimized by the moderator on the site
Hello,
To apply this code to columns that you need, please use the following VBA code:(Note: In the code, 5 is the row number contains the date, please change it to your need.)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRg As Range
Set xRg = Target.Worksheet.Cells(5, Target.Column)
If xRg <> Date Then
ActiveSheet.Protect Password:="111111"
MsgBox "Only today's date row can be edited!", vbInformation, "Kutools for Excel"
ElseIf xRg.Value = Date Then
ActiveSheet.Unprotect Password:="111111"
ActiveSheet.EnableSelection = xlNoRestrictions
End If
End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
Hi Im facing one problem, once i close the file and reopens it again on the same date, code doesnot work. pls help im stuck
This comment was minimized by the moderator on the site
Hi, rohit,
To keep the code, you should save your workbook as Excel Macro-Enabled Workbook format, please try, thank you!
This comment was minimized by the moderator on the site
Thanks for your help, Thanku so much buddy, It is a great help. and solved my tension.
Be safe
RegardsRohit Khanna
This comment was minimized by the moderator on the site
Thank you! Sorry, I did not get your reply until now, it might be a problem in my email.

It worked! Can't say thank you enough! I really appreciate that!
This comment was minimized by the moderator on the site
Hi,
Glad it can help you!
This comment was minimized by the moderator on the site
Hi,

I am trying to expand this to protect columns that do not include this current month or/and this current week. I tried to replace "Date" with "month" or "week", but did not work.

I have attached a sample for weeks sheet where user cannot edit or type in columns other than this week.

Any advice on that? or shall I use actual dates to reflect a day in the month?
This comment was minimized by the moderator on the site
Hello, I tried to do the same but to Protect all columns except today’s date column with VBA code by replacing "Selection.Row" with "Selection.Columns" and "E" with "5" (row number where dates are), but I keep receiving error 1004!

Any help please?

Thank you
This comment was minimized by the moderator on the site
Hi,

while running this code I am getting an error as shown in the figure
Also i am attaching a snapshot my excel where i want to make changes..

Can u guide in my code where should i make changes according to my excel file so that cells that contain only todays & future date can be editied ???
This comment was minimized by the moderator on the site
Hello, Karan,
Because there are merged cells in your table, the above code can not be applied correctly in merged cells table.
If you have any other good ideas, please comment here. Thank you!
This comment was minimized by the moderator on the site
As someone who is relatively new to VBA, would you mind explaining why xRow = 2 in Line 4?



Thanks
This comment was minimized by the moderator on the site
because in row no. 1 you have header
This comment was minimized by the moderator on the site
This works great. but how can I switch it to unlock a column based on dates in row 3?
This comment was minimized by the moderator on the site
Hello.....


I am using the code for Protect all rows except today’s date row........



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice 20161025
If Range("A" & Selection.Row).Value <> Date Then
ActiveSheet.Protect Password:="111111"
MsgBox "Only today's date row can be edited!", vbInformation, "Kutools for Excel"
ElseIf Range("E" & Selection.Row).Value = Date Then
ActiveSheet.Unprotect Password:="111111"
ActiveSheet.EnableSelection = xlNoRestrictions
End If
End Sub


After i save i and click on cell i get message only today's date row can be edited....but if i double click the cell the i can edit...pls help
This comment was minimized by the moderator on the site
hi is it possible to lock certain cells depending on the date that is directly above them in a column?
This comment was minimized by the moderator on the site
Hi, Lusis,
Can you give your problem more specifically? Or you can attach a screenshot as your problem.
Thank you!
This comment was minimized by the moderator on the site
Hi skyyang

Yes here is a screenshot. Hope this helps.
This comment was minimized by the moderator on the site
Here it is.
This comment was minimized by the moderator on the site
Hello, Lucis,
Do you mean to lock the columns which date is past, and only the columns of today and future days can be modified?
This comment was minimized by the moderator on the site
Correct! How would I go about that?
This comment was minimized by the moderator on the site
Hi, Luis,
How about the date cell in A1? Is it entered manually or entered with a formula =now()? If it is a formula cell, the locked columns will be changed with the date changes.
Looking forward to your reply!
This comment was minimized by the moderator on the site
Hi Skyyangg

yes the cell A1 has the =now() formula.

thanks!
This comment was minimized by the moderator on the site
Hi is it possible to lock columns by the date directly above the columns?
This comment was minimized by the moderator on the site
Private Sub worksheet_Change(ByVal Target As Range)

'Subscribe to http://youtube.com/excel10tutorial

'Support the channel by donating on http://patreon.com/excel10tutorial

Dim col As Range

'Set the correct sheet name here:

With ThisWorkbook.Sheets("AGOSTO-22")

.Unprotect "ABCDE"

For Each col In .UsedRange.Columns

col.EntireColumn.Locked = col.Range("A1").Value <> Date

Next col

.Protect "ABCDE"

.EnableSelection = xlNoRestrictions

End With

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