The VBA code DueDates() uses a custom subroutine 'PerformCopyAndClear' I have further…
- User
The VBA code DueDates() uses a custom subroutine 'PerformCopyAndClear' I have further down, a modified version of 'DueDates' How will the subroutine 'PerformCopyAndClear' need to be modified to suit.
Sub DueDates()
codeApplication.ScreenUpdating = False Dim currentMonth As Long currentMonth = Month(Date) If currentMonth >= 9 And currentMonth <= 12 Then ' Sep to Dec If Range("I1").Value > 0 Then PerformCopyAndClear Columns("E:E").Offset(1), Columns("F:F").Offset(1) End If If Range("J1").Value > 0 Then PerformCopyAndClear Columns("G:G").Offset(1), Columns("B:B").Offset(1), Columns("AE:AE").Offset(1) End If ElseIf currentMonth >= 1 And currentMonth <= 3 Then ' Jan to Mar If Range("J1").Value > 0 Then PerformCopyAndClear Columns("G:G").Offset(1), Columns("B:B").Offset(1) End If If Range("H1").Value > 0 Then PerformCopyAndClear Columns("C:C").Offset(1), Columns("D:D").Offset(1), Columns("AE:AE").Offset(1) End If ElseIf currentMonth >= 4 And currentMonth <= 8 Then ' Apr to Aug If Range("H1").Value > 0 Then PerformCopyAndClear Columns("C:C").Offset(1), Columns("D:D").Offset(1) End If If Range("I1").Value > 0 Then PerformCopyAndClear Columns("E:E").Offset(1), Columns("F:F").Offset(1), Columns("AE:AE").Offset(1) End If End If Application.ScreenUpdating = True Application.EnableEvents = True Me.Protect Password:="edit"End Sub
Private Sub PerformCopyAndClear(sourceColumn As Range, ParamArray destinationColumns() As Variant)
code - Assistant
The subroutine 'PerformCopyAndClear' needs to be modified to accept the new range arguments. Instead of using the 'sourceColumn' and 'destinationColumns' Range objects, the modified 'PerformCopyAndClear' subroutine should accept the new ranges as input parameters.
Here is the modified version of the 'PerformCopyAndClear' subroutine:
Private Sub PerformCopyAndClear(sourceRange As Range, ParamArray destinationRanges() As Variant)
codeMe.Unprotect Password:="edit" Application.EnableEvents = False sourceRange.Offset(1).Resize(sourceRange.Rows.Count - 1).Copy ' Exclude row 1 during copy Dim destinationRange As Variant For Each destinationRange In destinationRanges destinationRange.Offset(1).Resize(sourceRange.Rows.Count - 1).PasteSpecial xlPasteValues ' Paste excluding row 1 Next destinationRange sourceRange.Offset(1).Resize(sourceRange.Rows.Count - 1).ClearContents ' Clear excluding row 1 Application.CutCopyMode = False Application.EnableEvents = True Me.Protect Password:="edit" - User
In my modified 'DueDates' I am using ranges and do not use the Offset(1). How does this reflect on the subroutine 'PerformCopyAndClear' because I see that it still uses Offset(1)
- Assistant
If you are not using the Offset(1) method directly in your modified 'DueDates' subroutine and the ranges you are passing to the 'PerformCopyAndClear' subroutine already exclude the first row, then you can modify the 'PerformCopyAndClear' subroutine to remove the Offset(1) method calls as well.
Here is the modified 'PerformCopyAndClear' subroutine:
Private Sub PerformCopyAndClear(sourceRange As Range, ParamArray destinationRanges() As Variant)
codeMe.Unprotect Password:="edit" Application.EnableEvents = False sourceRange.Copy ' Exclude row 1 during copy Dim destinationRange As Variant For Each destinationRange In destinationRanges destinationRange.PasteSpecial xlPasteValues ' Paste excluding row 1 Next destinationRange sourceRange.ClearContents ' Clear excluding row 1 Application.CutCopyMode = False Application.EnableEvents = True Me.Protect Password:="edit" - User
The date in B1 = 05/02/24 The Date in C1 = 16/02/24 I need a VBA line that will proceed with an action if the date in in my Target D1 does not fall between the dates in B1 and C1. Something like this: If Target.Value < startDate And Target.Value > endDate Then
- Assistant
To check if the value in a target cell falls outside the range between the dates in B1 and C1, you can use the following VBA code:
vbaDim startDate As Date Dim endDate As Date startDate = Range("B1").Value endDate = Range("C1").Value If Target.Value < startDate Or Target.Value > endDate Then ' Proceed with the action here ' For example: MsgBox "Target value is outside the date range!" End IfIn this code snippet, we first assign the values in B1 and C1 to the variables
startDateandendDate, respectively. Then, we use an if statement to check if the value in theTargetcell (assuming you have already defined it elsewhere in your code) is either less than thestartDateor greater than theendDate. If the condition is met, you can proceed with the desired action. For demonstration purposes, the code displays a message box indicating that the target value is outside the date range. You can replace this line with your specific action.