JohnGow383
Board Regular
- Joined
- Jul 6, 2021
- Messages
- 141
- Office Version
- 2013
- Platform
- Windows
Hi.
I have an event change macro that copies comments from one cell to another sheet. It's rather long winded and I'm not great with syntax but was able to generate most of the code to get it to what I want to do. I wanted the comments to be concatenated with the current date but all as text. The child macro does the following:
1. On the 2nd sheet it formats a cell to be text, then it looks at the first sheet date cell and says the date on the first sheet = the cell on the 2nd sheet with a text format of "mmm d, yyyy".
2. The comments from the 1st sheet are copied and pasted into another cell on the 2nd sheet.
3. Using a 3rd cell, I have a FormulaR1C1 to concatenate the two cells with a hypen in the middle.
4. This cell then is copied and values pasted into the main comment cell and then it goes back to the first sheet after deleting the working cells on the 2nd sheet from above.
5. The final comment is something like: May 23, 2022 - Comments blah blah etc.
This works fine until I protect the sheet with code. The code for the copying and pasting is as follows:
A possible solution would be to clean up the above code. I just couldn't find a way easily to copy a date into text without formatting the cell prior to the copy and paste.
I have the following macro to quickly protect my selected sheets. I have editobjects successfully enabled but when I trying to allow formatting it doesn't work. Here is my protect ws code:
Any help much appreciated. Thanks in advance.
I have an event change macro that copies comments from one cell to another sheet. It's rather long winded and I'm not great with syntax but was able to generate most of the code to get it to what I want to do. I wanted the comments to be concatenated with the current date but all as text. The child macro does the following:
1. On the 2nd sheet it formats a cell to be text, then it looks at the first sheet date cell and says the date on the first sheet = the cell on the 2nd sheet with a text format of "mmm d, yyyy".
2. The comments from the 1st sheet are copied and pasted into another cell on the 2nd sheet.
3. Using a 3rd cell, I have a FormulaR1C1 to concatenate the two cells with a hypen in the middle.
4. This cell then is copied and values pasted into the main comment cell and then it goes back to the first sheet after deleting the working cells on the 2nd sheet from above.
5. The final comment is something like: May 23, 2022 - Comments blah blah etc.
This works fine until I protect the sheet with code. The code for the copying and pasting is as follows:
VBA Code:
Sub CopyDailyComment() 'copies any comments into Log Entries sheet with added date
Sheets("LOG Entries").Range("k2").NumberFormat = "@"
Sheets("LOG Entries").Range("k2") = Format(Sheets("NOON Figs").Range("B2"), "mmm d, yyyy")
Sheets("NOON Figs").Select
Range("H13:K14").Select
Selection.Copy
Sheets("LOG Entries").Select
Range("L2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("M2").Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = "=RC[-2]&"" - ""&RC[-1]"
Range("M2").Select
Selection.Copy
Range("T13:W14").Select
ActiveSheet.Paste Link:=True
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("K2:M2").ClearContents
Sheets("NOON Figs").Select
Application.CutCopyMode = False
End Sub
A possible solution would be to clean up the above code. I just couldn't find a way easily to copy a date into text without formatting the cell prior to the copy and paste.
I have the following macro to quickly protect my selected sheets. I have editobjects successfully enabled but when I trying to allow formatting it doesn't work. Here is my protect ws code:
VBA Code:
Sub ProtectSelectedWorksheets() 'Shortcut is Ctr + Shift P
Dim ws As Worksheet
Dim sheetArray As Variant
Dim myPassword As Variant
'Set the password - Please use 63360
myPassword = Application.InputBox(prompt:="Enter password", _
Title:="Password", Type:=2)
'The User clicked Cancel
If myPassword = False Then Exit Sub
'Capture the selected sheets
Set sheetArray = ActiveWindow.SelectedSheets
'Loop through each worksheet in the active workbook
For Each ws In sheetArray
On Error Resume Next
ws.Select 'Select the worksheet
ws.Protect Password:=myPassword, DrawingObjects:=False, Contents:=True, Scenarios:= _
True, AllowFormattingCells:=True 'Protect each worksheet but enables edit objects (for Comment generating macros)
On Error GoTo 0
Next ws
sheetArray.Select
End Sub
Any help much appreciated. Thanks in advance.