Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50123

Data validation on multiple sheets.

$
0
0
Hello,

I'm currently using this code:
Code:

If Not Application.Intersect(Target, Range("B1:E100")) Is Nothing Then
    If Range("B" & Target.Row) = "" And Range("C" & Target.Row) = "" And Range("D" & Target.Row) = "" And Range("E" & Target.Row) = "" Then
        Range("A" & Target.Validation).Delete
    Else
        With Range("A" & Target.Row).Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:= _
            "=IF(NOT(AND(B" & Target.Row & "="""",C" & Target.Row & "="""",D" & Target.Row & "="""",E" & Target.Row & "="""")),Priority,"""")"
        End With
    End If
 End If

to insert data validation on entries in a spreadsheet.

I then use a variation of this code to transfer entries from one sheet to the other, and perhaps back again:
Code:

Private Sub UpdateHistory1_Click()

 Dim xlRng As Range
   
    On Error GoTo UpdateHistory1_Click_ErrorHandler

    If ActiveSheet.ProtectContents Then
        MsgBox "Sheet protected! Please select the, 'Edit Sheet' button, and" & _
            " enter the password before this button can be used.", vbOKOnly + vbInformation, "Update History"
        GoTo UpdateHistory1_Click_Proc_Exit
    End If

    Application.ScreenUpdating = False
   
    Dim ws As Worksheet, ms As Worksheet
    Set ws = Sheets("Current Maintenance") 'Current worksheet
    Set ms = Sheets("History Maintenance") 'History
       
    With ms
        .Unprotect "123steel"
       
        'heading:
        .Range(.Cells(6, 1), .Cells(6, 8)).Value = Array("Priority", _
                                                        "Today's Date", _
                                                        "Equipment", _
                                                        "Location", _
                                                        "Description", _
                                                        "Expected Time of Completion", _
                                                        "Completed? y or n", _
                                                        "Time of Completion")
   
        End With
       
        With ws.ListObjects("Table1").Range
       
            .AutoFilter 7, "y" 'finds y in 7th column (G)
            If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
              .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible).Copy
              ms.Cells(ms.Cells(ms.Rows.Count, 2).End(xlUp).Row + 1, 1).PasteSpecial Paste:=xlPasteValues
              .Resize(.Rows.Count - 1).Offset(1).EntireRow.Delete Shift:=xlUp
            End If
            .AutoFilter
           
        End With
       
UpdateHistory1_Click_Proc_Exit:
    On Error GoTo 0
    If Not ActiveSheet.ProtectContents Then ActiveSheet.Protect "123steel"
    Application.ScreenUpdating = True
    Exit Sub
UpdateHistory1_Click_ErrorHandler:
    MsgBox "Error: " & Err.Number & " (" & Err.Description & ") in Sub 'UpdateHistory1_Click' of VBA Document 'Sheet11'.", vbOKOnly + vbCritical, "Error"
    Resume UpdateHistory1_Click_Proc_Exit
   
End Sub

If I take an entry, move it to a different sheet, and decide I want to move that entry back to its original sheet, how can I return the data validation back to the cell?

I have attached my workbook.
The password, when prompted, is "MillSteel"

I want data validation to only be present on "Current ____" sheet. not "History ___"
Attached Files

Viewing all articles
Browse latest Browse all 50123

Trending Articles