In column K, from K2 downwards, I have formulas that reference sheets in my workbook.…
- User
In column K, from K2 downwards, I have formulas that reference sheets in my workbook. The formulas are like this: =IF(Day!2<>"",TODAY()- Day!2,""). In column AA, from AA2 downwards, I have text values that decribe references to sheets in my workbook. The text values are like this: Day!2. How can I write the same formula in L2 using the Indirect formula in AA2
- Assistant
To create a formula in cell L2 that uses the
INDIRECTfunction to reference the text in cell AA2, you can modify your original formula to look like this:=IF(INDIRECT(AA2)<>"", TODAY() - INDIRECT(AA2), "")Explanation:
INDIRECT(AA2)will evaluate the text in cell AA2 (which is "Day!2" in your example) as a reference.- If that reference is not empty (<>""), it will perform the calculation
TODAY() - INDIRECT(AA2). - If it is empty, it will return an empty string ("").
Just place this formula in cell L2, and it will dynamically reference the sheet and cell based on the content of AA2. Adjust the cell format in column L if needed to display the result correctly based on your calculations.
- User
Can you please write me a VBA module that will do the following. Check the active sheet and check if there is a date value in column L from L2 to the last entry. If there are no date values, then exit the sub. If there is a date value, for each row that contains a date value, check if each date in the row of column L exceeds each date in the same row of column G by 7 days. If all the dates in column L do not exceed the respective row date is column G, exit the sub. If any date in in column L exceeds the respective row date is column G, Then collect all the data for each row where the condition is true and pop up a message in this format. "Task shown below has exceeded Epected End Date" line space "To move to next period, Double Click End Date" line space "This Copies Task to Notepad & Deletes the Task"line space "Use this to Create a new Task period in Planner." double line space Then, present the first four words of the value in column A of each row where the condition is true and seperate each condition by a line space.
- Assistant
- User
I am getting a 'Type Mismatch' Error on the line: If ws.Cells(i, "L").Value > ws.Cells(i, "G").Value + 14 Then if the date in column G is greater than the date in column L
Sub CheckWeekDatesAndNotify() Dim ws As Worksheet Dim lastRow As Long Dim i As Long Dim taskMessages As String Dim hasExceeded As Boolean
- Assistant
- User
In my workbook, all the sheets are protected How do I Unprotect and then Protect the sheets ws.Name = "Day" Or ws.Name = "Week" Or ws.Name = "Fortnight" Or ws.Name = "Month" Or ws.Name = "QtrYear" Or ws.Name = "HalfYear" Or ws.Name = "Year" for this VBA code:
Sub CopyExpiredTasks()
Dim ws As Worksheet Dim lastRow As Long, i As Long Dim targetSheet As Worksheet, targetLastRow As Long Set targetSheet = ThisWorkbook.Sheets("Expired") targetSheet.Unprotect Password:="edit" targetSheet.Range("A2:L100").ClearContents For Each ws In ThisWorkbook.Worksheets If ws.Name = "Day" Or ws.Name = "Week" Or ws.Name = "Fortnight" Or ws.Name = "Month" Or ws.Name = "QtrYear" Or ws.Name = "HalfYear" Or ws.Name = "Year" Then lastRow = ws.Cells(Rows.Count, "G").End(xlUp).Row For i = 2 To lastRow If ws.Cells(i, "G").Value < Date Then targetLastRow = targetSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1 ws.Range("A" & i & ":K" & i).Copy targetSheet.Range("A" & targetLastRow).PasteSpecial Paste:=xlPasteValues targetSheet.Cells(targetLastRow, "L").Value = ws.Name End If Next i End If Next ws MsgBox "All Expired Tasks Recorded", vbInformation, "EXPIRED TASKS"targetSheet.Protect Password:="edit" End Sub
- Assistant
- User
How do I write the code to prevent screed updates like ScreenSometing = False
- Assistant
- User
Can you please write me two VBA modules that will do the following:
The first VBA event will do the following: When I double click on a cell in column G that contains a date value from G2 downwards, Record the Target address the call and pass the address to the second VBA module.
The second VBA module will do the following: For the Target Address recieved, it copies the row values from A to K, and writes it to a new NotePad text document, each cell on a different line. Then after the text document has opened,
It will pop up a Yes No message "Do you want to create a new Period for this task" line break "YES - to delete the task and go to Planner" line break "to create a new task period in Planner Form." double line break "No - to abort this procedure"
If I click No, exit the sub and close the open instance of NotePad. If I click Yes, delete the Target row and Activate sheet Planner and pop up a message "Use NotePad entry to complete a new Planner Form", vbInformation, "NEW FORM"
- Assistant
- User
Does this prevent the Save dialogue from opening when closing NotePad: If response = vbNo Then ' Close the Notepad (if it's open) NotepadApp.Exec "taskkill /IM notepad.exe /F" ' Force close Notepad Exit Sub
- Assistant
The line you included with
NotepadApp.Exec "taskkill /IM notepad.exe /F"is designed to forcefully close any running instance of Notepad without prompting for a "Save" confirmation. By using this approach, you are essentially instructing Windows to terminate the Notepad process immediately, which will indeed bypass the "Save" dialogue that normally appears if you try to close Notepad after making changes to a document. - User
When NotePad opened, it had only written the row values from G to K. I want it to write the row values from A to K: Sub WriteToNotepad(TargetAddress As String) Dim ws As Worksheet Dim taskRow As Range Dim NotepadPath As String Dim FileNumber As Integer Dim NotepadApp As Object Dim response As VbMsgBoxResult
Set ws = ThisWorkbook.ActiveSheet Set taskRow = ws.Range(TargetAddress) ' Specify the path and name for the Notepad document NotepadPath = Environ$("TEMP") & "\TaskDetails.txt" FileNumber = FreeFile ' Open the text file for writing Open NotepadPath For Output As #FileNumber Dim i As Long ' Loop through columns A to K and write each value to the text file For i = 1 To 11 ' Columns A to K Print #FileNumber, taskRow.Cells(1, i).Value Next i ' Close the text file Close #FileNumber ' Open notepad showing the created text file Set NotepadApp = CreateObject("WScript.Shell") NotepadApp.Run NotepadPath ' Show message box to the user with Yes/No options response = MsgBox("Do you want to create a new Period for this task?" & vbCrLf & _ "YES - to delete the task and go to Planner" & vbCrLf & _ "to create a new task period in Planner Form." & vbCrLf & _ "NO - to abort this procedure", vbYesNo + vbQuestion, "Create New Period") ' Handle user response If response = vbNo Then ' Close the Notepad (if it's open) NotepadApp.Exec "taskkill /IM notepad.exe /F" ' Force close Notepad Exit Sub ElseIf response = vbYes Then ' Delete the row from the worksheet Application.DisplayAlerts = False ' Turn off alerts for row deletion taskRow.EntireRow.Delete Application.DisplayAlerts = True ' Activate the Planner sheet On Error Resume Next ThisWorkbook.Sheets("Planner").Activate On Error GoTo 0 ' Inform the user to fill out the new Planner Form MsgBox "Use NotePad entry to complete a new Planner Form", vbInformation, "NEW FORM" End If - Assistant
- User
When I double click on a cell in column G to activate the module 'Sub WriteToNotepad(TargetAddress As String)', it is still only writing the values from G to K and not from A to K, even though values are present in the entire row.
- Assistant
- User
Thanks, it worked as expected
- Assistant
You're welcome! I'm glad to hear that it worked as you expected. If you have any more questions or need further assistance with VBA or any other topic, feel free to ask. Happy coding!
- User
In the VBA event, for the first part 'If Target.Column = 1', I have included 'Cancel = True' at the start of the event. Is this the correct position to enter 'Cancel = True' or should it be entered further down the particular event.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim response As VbMsgBoxResult Dim rangeToCopy As Range
' Check if double-click occurred in column A If Target.Column = 1 Then ' Prevent entering edit mode on double-click Cancel = True ' Ask user if they want to duplicate the task response = MsgBox("Do you want to duplicate the task?", vbQuestion + vbYesNo) If response = vbYes Then Me.Unprotect Password:="edit" Application.EnableEvents = False Application.ScreenUpdating = False ' Define the range to copy from column A to K of the double-clicked cell Set rangeToCopy = Range(Target, Target.Offset(, 10)) ' Insert a new row below the double-clicked cell Target.EntireRow.Insert Shift:=xlDown ' Copy the range to the newly inserted row rangeToCopy.Copy Destination:=Target.Offset(-1) Target.Offset(-1, 8).Value = "ARCHIVED. Enter 'Completed' to delete" Target.Offset(0, 10).Value = "ADJUST. Execution & Status" ' Display the message MsgBox "Duplicate Row of Task has been created" & vbCrLf & _ "In original row, enter complete to close the row" & vbCrLf & _ "to archive progress of the task", vbInformation, "TASK PROGRESS" Application.EnableEvents = True Application.ScreenUpdating = True Me.Protect Password:="edit" End If End If - Assistant
- User
Thnaks for the explanation.
- Assistant
You're welcome! I'm glad I could help. If you have any more questions or need further assistance in the future, whether it's about VBA or anything else, don't hesitate to reach out. Happy coding!