In this VBA event, can you please add an extra requiremet that does the following: If I…
- User
In this VBA event, can you please add an extra requiremet that does the following: If I choose yes, and there are no values in i = 2 To lastColumn, then pop up a message "No Leave to Transfer" and GoTo Clearx.
Sub Copy28To15() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")
' Write 'x' to CV28 ws.Range("CV28").Value = "x" ' Calculate CV28 ws.Calculate ' Prompt user for confirmation Dim response28 As VbMsgBoxResult response28 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response28 = vbNo Then ' Clear CV28 before exiting ws.Range("CV28").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(28, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(15, j).Value = ws.Cells(28, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next iClearx:
' Clear the contents of CV28 after the loop ws.Range("CV28").ClearContents ' Calculate CV28 again ws.CalculateEnd Sub
- Assistant
- User
Please do the same for:
Sub Copy29To16() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")' Write 'x' to CV29 ws.Range("CV29").Value = "x" ' Calculate CV29 ws.Calculate ' Prompt user for confirmation Dim response29 As VbMsgBoxResult response29 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response29 = vbNo Then ' Clear CV29 before exiting ws.Range("CV29").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(29, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(16, j).Value = ws.Cells(29, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i - Assistant
- User
same again for:
Sub Copy30To17() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")' Write 'x' to CV30 ws.Range("CV30").Value = "x" ' Calculate CV30 ws.Calculate ' Prompt user for confirmation Dim response30 As VbMsgBoxResult response30 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response30 = vbNo Then ' Clear CV30 before exiting ws.Range("CV30").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(30, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(17, j).Value = ws.Cells(30, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i - Assistant
- User
same again for:
Sub Copy31To18() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")' Write 'x' to CV31 ws.Range("CV31").Value = "x" ' Calculate CV31 ws.Calculate ' Prompt user for confirmation Dim response31 As VbMsgBoxResult response31 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response31 = vbNo Then ' Clear CV31 before exiting ws.Range("CV31").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(31, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(18, j).Value = ws.Cells(31, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i - Assistant
- User
same again for:
Sub Copy32To19() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")' Write 'x' to CV32 ws.Range("CV32").Value = "x" ' Calculate CV32 ws.Calculate ' Prompt user for confirmation Dim response32 As VbMsgBoxResult response32 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response32 = vbNo Then ' Clear CV28 before exiting ws.Range("CV32").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(32, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(19, j).Value = ws.Cells(32, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i - Assistant
- User
same again for:
Sub Copy33To20() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")' Write 'x' to CV33 ws.Range("CV33").Value = "x" ' Calculate CV33 ws.Calculate ' Prompt user for confirmation Dim response33 As VbMsgBoxResult response33 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response33 = vbNo Then ' Clear CV33 before exiting ws.Range("CV33").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(33, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(20, j).Value = ws.Cells(33, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i - Assistant
- User
and lastly, the same again for: Sub Copy34To21() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Leave")
' Write 'x' to CV34 ws.Range("CV34").Value = "x" ' Calculate CV34 ws.Calculate ' Prompt user for confirmation Dim response34 As VbMsgBoxResult response34 = MsgBox("Do you want to copy the row" & vbCrLf & "to the LEAVE TABLE?", vbYesNo + vbInformation, "COPY TO LEAVE") If response34 = vbNo Then ' Clear CV34 before exiting ws.Range("CV34").ClearContents ws.Calculate Exit Sub End If Dim lastColumn As Integer lastColumn = 94 Dim i As Integer For i = 2 To lastColumn If ws.Cells(34, i).Value <> "" Then ' Change range A Dim currentDate As Date On Error Resume Next currentDate = CDate(ws.Cells(27, i).Value) On Error GoTo 0 If IsDate(currentDate) And i <= lastColumn Then Dim j As Integer For j = 2 To 94 If ws.Cells(14, j).Value = currentDate And j <= lastColumn Then ws.Cells(21, j).Value = ws.Cells(34, i).Value ' Change range B Change range A Exit For End If Next j Else MsgBox "Invalid date format or date outside range in cell " & ws.Cells(27, i).Address End If End If Next i ' Clear the contents of CV34 after the loop ws.Range("CV34").ClearContents ' Calculate CV34 again ws.Calculate - Assistant