Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Macro not running in Protect Sheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Akash - 16 Jan 2008 12:39 GMT
Hi,

I have a macro, With the help of this macro, as soon as u write
anything in Column A it would automatically  throws a Current Date in
Column G:

Dim LastRow, LastCol, CurRow, CurCol As Integer

Private Sub Worksheet_Change(ByVal Target As Range)
   If LastCol = 1 Then
       CurRow = ActiveCell.Row
       CurCol = ActiveCell.Column
       'MsgBox ActiveCell.Row
       'MsgBox ActiveCell.Column

       'MsgBox Target

       If Sheet1.Cells(LastRow, 7).Value = "" Then
Sheet1.Cells(LastRow, 7).Value = Date
       Cells(LastRow, 4).Select
   End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   LastRow = ActiveCell.Row
   LastCol = ActiveCell.Column
   'MsgBox ActiveCell.Row
   'MsgBox ActiveCell.Column

End Sub

There are other formulas in the Excel Sheet. I had protected the sheet
to hide the formula. but as soon as i protected the sheet, my macro is
not working.

Can u help me how can i run the macro even after i protect the sheet.

Is there any way.

Thanks

Akash
Per Jessen - 16 Jan 2008 13:15 GMT
Hi Akash

You can not change any cell which is protected.

So you have to unprotect the cell before you can add the date.

Private Sub Worksheet_Change(ByVal Target As Range)
   If LastCol = 1 Then
       CurRow = ActiveCell.Row
       CurCol = ActiveCell.Column
       'MsgBox ActiveCell.Row
       'MsgBox ActiveCell.Column

       'MsgBox Target
       With Sheets(Sheet1)

           If .Cells(LastRow, 7).Value = "" Then
               .Unprotect
               .Cells(LastRow, 7).Value = Date
               .Cells(LastRow, 4).Select
               .Protect
           End If
       End With
   End If
End Sub

Regards,

Per

> Hi,
>
[quoted text clipped - 38 lines]
>
> Akash
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.