VBA Userform data change check












0















I am using a userform to update data in a worksheet, I have an update command button to copy the data from the 'data' worksheet to the 'archive' and replace in the 'data' worksheet (essentially the 'archive' is a log of all previous lines and the 'data' is the most recent information)



The information is changed in text boxes and combo boxes



What Im struggling with is for the 'update' cmdbutton to first check if any changes where made before copying the data, if not I want a msg box to read 'no change in data, please close form'



Here is the code for the userform so far:



Private Sub cmdUpdate_Click()
' To write edited info of userform2 to Sheets("Data")
Dim LastRow As Long
Dim ABnum As Double
Dim ABrng As Range
Dim WriteRow As Long

'error statement
On Error GoTo errHandler:
'hold in memory and stop screen flicker
Application.ScreenUpdating = False
' Make sure we're on the right sheet
With Sheets("Data")
' Get the last row used so can set up the search range
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
' Set the range to search for the AB number
Set ABrng = .Range("A1:A" & LastRow)
' Get the AB number from what is selected on userform2
ABnum = txtup1.Value
' Get the row of sheet for this AB number
WriteRow = Application.Match(ABnum, ABrng, 0)
' Make this AB number the active cell
With .Cells(WriteRow, 1)
' Write in all the editable options
Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
.Offset(0, 4) = cboup3.Value
.Offset(0, 5) = cboup4.Value
.Offset(0, 6) = cboup5.Value
.Offset(0, 7) = cboup6.Value
.Offset(0, 8) = Date
.Offset(0, 9) = txtrev.Value
.Offset(0, 12) = txtup9.Value
.Offset(0, 13) = txtup8.Value
End With
End With
' Filter the Data
FilterMe
' Close the form
Unload Me

MsgBox ("Enquiry E0" + Me.txtup1.Text + " has been updated")

errHandler:
'Protect all sheets if error occurs
'Protect_All
'show error information in a messagebox
If Err.Number <> 0 Then
MsgBox "Error " & Err.Number & " just occured."
End If

End Sub









share|improve this question



























    0















    I am using a userform to update data in a worksheet, I have an update command button to copy the data from the 'data' worksheet to the 'archive' and replace in the 'data' worksheet (essentially the 'archive' is a log of all previous lines and the 'data' is the most recent information)



    The information is changed in text boxes and combo boxes



    What Im struggling with is for the 'update' cmdbutton to first check if any changes where made before copying the data, if not I want a msg box to read 'no change in data, please close form'



    Here is the code for the userform so far:



    Private Sub cmdUpdate_Click()
    ' To write edited info of userform2 to Sheets("Data")
    Dim LastRow As Long
    Dim ABnum As Double
    Dim ABrng As Range
    Dim WriteRow As Long

    'error statement
    On Error GoTo errHandler:
    'hold in memory and stop screen flicker
    Application.ScreenUpdating = False
    ' Make sure we're on the right sheet
    With Sheets("Data")
    ' Get the last row used so can set up the search range
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    ' Set the range to search for the AB number
    Set ABrng = .Range("A1:A" & LastRow)
    ' Get the AB number from what is selected on userform2
    ABnum = txtup1.Value
    ' Get the row of sheet for this AB number
    WriteRow = Application.Match(ABnum, ABrng, 0)
    ' Make this AB number the active cell
    With .Cells(WriteRow, 1)
    ' Write in all the editable options
    Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
    .Offset(0, 4) = cboup3.Value
    .Offset(0, 5) = cboup4.Value
    .Offset(0, 6) = cboup5.Value
    .Offset(0, 7) = cboup6.Value
    .Offset(0, 8) = Date
    .Offset(0, 9) = txtrev.Value
    .Offset(0, 12) = txtup9.Value
    .Offset(0, 13) = txtup8.Value
    End With
    End With
    ' Filter the Data
    FilterMe
    ' Close the form
    Unload Me

    MsgBox ("Enquiry E0" + Me.txtup1.Text + " has been updated")

    errHandler:
    'Protect all sheets if error occurs
    'Protect_All
    'show error information in a messagebox
    If Err.Number <> 0 Then
    MsgBox "Error " & Err.Number & " just occured."
    End If

    End Sub









    share|improve this question

























      0












      0








      0








      I am using a userform to update data in a worksheet, I have an update command button to copy the data from the 'data' worksheet to the 'archive' and replace in the 'data' worksheet (essentially the 'archive' is a log of all previous lines and the 'data' is the most recent information)



      The information is changed in text boxes and combo boxes



      What Im struggling with is for the 'update' cmdbutton to first check if any changes where made before copying the data, if not I want a msg box to read 'no change in data, please close form'



      Here is the code for the userform so far:



      Private Sub cmdUpdate_Click()
      ' To write edited info of userform2 to Sheets("Data")
      Dim LastRow As Long
      Dim ABnum As Double
      Dim ABrng As Range
      Dim WriteRow As Long

      'error statement
      On Error GoTo errHandler:
      'hold in memory and stop screen flicker
      Application.ScreenUpdating = False
      ' Make sure we're on the right sheet
      With Sheets("Data")
      ' Get the last row used so can set up the search range
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
      ' Set the range to search for the AB number
      Set ABrng = .Range("A1:A" & LastRow)
      ' Get the AB number from what is selected on userform2
      ABnum = txtup1.Value
      ' Get the row of sheet for this AB number
      WriteRow = Application.Match(ABnum, ABrng, 0)
      ' Make this AB number the active cell
      With .Cells(WriteRow, 1)
      ' Write in all the editable options
      Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
      .Offset(0, 4) = cboup3.Value
      .Offset(0, 5) = cboup4.Value
      .Offset(0, 6) = cboup5.Value
      .Offset(0, 7) = cboup6.Value
      .Offset(0, 8) = Date
      .Offset(0, 9) = txtrev.Value
      .Offset(0, 12) = txtup9.Value
      .Offset(0, 13) = txtup8.Value
      End With
      End With
      ' Filter the Data
      FilterMe
      ' Close the form
      Unload Me

      MsgBox ("Enquiry E0" + Me.txtup1.Text + " has been updated")

      errHandler:
      'Protect all sheets if error occurs
      'Protect_All
      'show error information in a messagebox
      If Err.Number <> 0 Then
      MsgBox "Error " & Err.Number & " just occured."
      End If

      End Sub









      share|improve this question














      I am using a userform to update data in a worksheet, I have an update command button to copy the data from the 'data' worksheet to the 'archive' and replace in the 'data' worksheet (essentially the 'archive' is a log of all previous lines and the 'data' is the most recent information)



      The information is changed in text boxes and combo boxes



      What Im struggling with is for the 'update' cmdbutton to first check if any changes where made before copying the data, if not I want a msg box to read 'no change in data, please close form'



      Here is the code for the userform so far:



      Private Sub cmdUpdate_Click()
      ' To write edited info of userform2 to Sheets("Data")
      Dim LastRow As Long
      Dim ABnum As Double
      Dim ABrng As Range
      Dim WriteRow As Long

      'error statement
      On Error GoTo errHandler:
      'hold in memory and stop screen flicker
      Application.ScreenUpdating = False
      ' Make sure we're on the right sheet
      With Sheets("Data")
      ' Get the last row used so can set up the search range
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
      ' Set the range to search for the AB number
      Set ABrng = .Range("A1:A" & LastRow)
      ' Get the AB number from what is selected on userform2
      ABnum = txtup1.Value
      ' Get the row of sheet for this AB number
      WriteRow = Application.Match(ABnum, ABrng, 0)
      ' Make this AB number the active cell
      With .Cells(WriteRow, 1)
      ' Write in all the editable options
      Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
      .Offset(0, 4) = cboup3.Value
      .Offset(0, 5) = cboup4.Value
      .Offset(0, 6) = cboup5.Value
      .Offset(0, 7) = cboup6.Value
      .Offset(0, 8) = Date
      .Offset(0, 9) = txtrev.Value
      .Offset(0, 12) = txtup9.Value
      .Offset(0, 13) = txtup8.Value
      End With
      End With
      ' Filter the Data
      FilterMe
      ' Close the form
      Unload Me

      MsgBox ("Enquiry E0" + Me.txtup1.Text + " has been updated")

      errHandler:
      'Protect all sheets if error occurs
      'Protect_All
      'show error information in a messagebox
      If Err.Number <> 0 Then
      MsgBox "Error " & Err.Number & " just occured."
      End If

      End Sub






      excel vba excel-vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 12:24









      James HurstJames Hurst

      245




      245
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The easiest way would be to write a function to compare the values.



          Private Sub cmdUpdate_Click()
          ' To write edited info of userform2 to Sheets("Data")
          Dim LastRow As Long
          Dim ABnum As Double
          Dim ABrng As Range
          Dim WriteRow As Long

          'error statement
          On Error GoTo errHandler:
          'hold in memory and stop screen flicker
          Application.ScreenUpdating = False
          ' Make sure we're on the right sheet
          With Sheets("Data")
          ' Get the last row used so can set up the search range
          LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          ' Set the range to search for the AB number
          Set ABrng = .Range("A1:A" & LastRow)
          ' Get the AB number from what is selected on userform2
          ABnum = txtenqup.Value
          ' Get the row of sheet for this AB number
          WriteRow = Application.Match(ABnum, ABrng, 0)
          ' Make this AB number the active cell
          With .Cells(WriteRow, 1)
          'Check for changes

          If Not hasValuePairsChanges(.Offset(0, 4).Value, cboup3.Value, _
          .Offset(0, 5).Value, cboup4.Value, _
          .Offset(0, 6).Value, cboup5.Value, _
          .Offset(0, 7).Value, cboup6.Value, _
          CDate(.Offset(0, 8).Value), Date, _
          CDbl(.Offset(0, 9).Value), CDbl(txtrev.Value), _
          .Offset(0, 12).Value, txtnotes.Value, _
          .Offset(0, 13).Value, txtdtime.Value) Then
          MsgBox "No Change in Data", vbInformation, ""
          Exit Sub
          End If

          ' Write in all the editable options
          Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
          .Offset(0, 4) = cboup3.Value
          .Offset(0, 5) = cboup4.Value
          .Offset(0, 6) = cboup5.Value
          .Offset(0, 7) = cboup6.Value
          .Offset(0, 8) = Date
          .Offset(0, 9) = txtrev.Value
          .Offset(0, 12) = txtnotes.Value
          .Offset(0, 13) = txtdtime.Value
          End With
          End With
          ' Filter the Data
          FilterMe
          ' Close the form
          Unload Me

          MsgBox ("Enquiry E0" + Me.txtenqup.Text + " has been updated")


          errHandler:
          'Protect all sheets if error occurs
          'Protect_All
          'show error information in a messagebox
          If Err.Number <> 0 Then
          MsgBox "Error " & Err.Number & " just occured."
          End If



          End Sub

          Function hasValuePairsChanges(ParamArray Args() As Variant) As Boolean
          Dim n As Long

          For n = 0 To UBound(Args) Step 2
          If Not Args(n) = Args(n + 1) Then
          hasValuePairsChanges = True
          Exit Function
          End If
          Next
          End Function





          share|improve this answer


























          • Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

            – James Hurst
            Nov 15 '18 at 13:58











          • @JamesHurst at what line did the error occur?

            – TinMan
            Nov 15 '18 at 14:00











          • ill disable the error handling

            – James Hurst
            Nov 15 '18 at 14:04











          • @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

            – TinMan
            Nov 15 '18 at 14:04











          • For n = 0 To UBound(args) Step 2

            – James Hurst
            Nov 15 '18 at 14:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319475%2fvba-userform-data-change-check%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The easiest way would be to write a function to compare the values.



          Private Sub cmdUpdate_Click()
          ' To write edited info of userform2 to Sheets("Data")
          Dim LastRow As Long
          Dim ABnum As Double
          Dim ABrng As Range
          Dim WriteRow As Long

          'error statement
          On Error GoTo errHandler:
          'hold in memory and stop screen flicker
          Application.ScreenUpdating = False
          ' Make sure we're on the right sheet
          With Sheets("Data")
          ' Get the last row used so can set up the search range
          LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          ' Set the range to search for the AB number
          Set ABrng = .Range("A1:A" & LastRow)
          ' Get the AB number from what is selected on userform2
          ABnum = txtenqup.Value
          ' Get the row of sheet for this AB number
          WriteRow = Application.Match(ABnum, ABrng, 0)
          ' Make this AB number the active cell
          With .Cells(WriteRow, 1)
          'Check for changes

          If Not hasValuePairsChanges(.Offset(0, 4).Value, cboup3.Value, _
          .Offset(0, 5).Value, cboup4.Value, _
          .Offset(0, 6).Value, cboup5.Value, _
          .Offset(0, 7).Value, cboup6.Value, _
          CDate(.Offset(0, 8).Value), Date, _
          CDbl(.Offset(0, 9).Value), CDbl(txtrev.Value), _
          .Offset(0, 12).Value, txtnotes.Value, _
          .Offset(0, 13).Value, txtdtime.Value) Then
          MsgBox "No Change in Data", vbInformation, ""
          Exit Sub
          End If

          ' Write in all the editable options
          Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
          .Offset(0, 4) = cboup3.Value
          .Offset(0, 5) = cboup4.Value
          .Offset(0, 6) = cboup5.Value
          .Offset(0, 7) = cboup6.Value
          .Offset(0, 8) = Date
          .Offset(0, 9) = txtrev.Value
          .Offset(0, 12) = txtnotes.Value
          .Offset(0, 13) = txtdtime.Value
          End With
          End With
          ' Filter the Data
          FilterMe
          ' Close the form
          Unload Me

          MsgBox ("Enquiry E0" + Me.txtenqup.Text + " has been updated")


          errHandler:
          'Protect all sheets if error occurs
          'Protect_All
          'show error information in a messagebox
          If Err.Number <> 0 Then
          MsgBox "Error " & Err.Number & " just occured."
          End If



          End Sub

          Function hasValuePairsChanges(ParamArray Args() As Variant) As Boolean
          Dim n As Long

          For n = 0 To UBound(Args) Step 2
          If Not Args(n) = Args(n + 1) Then
          hasValuePairsChanges = True
          Exit Function
          End If
          Next
          End Function





          share|improve this answer


























          • Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

            – James Hurst
            Nov 15 '18 at 13:58











          • @JamesHurst at what line did the error occur?

            – TinMan
            Nov 15 '18 at 14:00











          • ill disable the error handling

            – James Hurst
            Nov 15 '18 at 14:04











          • @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

            – TinMan
            Nov 15 '18 at 14:04











          • For n = 0 To UBound(args) Step 2

            – James Hurst
            Nov 15 '18 at 14:06
















          1














          The easiest way would be to write a function to compare the values.



          Private Sub cmdUpdate_Click()
          ' To write edited info of userform2 to Sheets("Data")
          Dim LastRow As Long
          Dim ABnum As Double
          Dim ABrng As Range
          Dim WriteRow As Long

          'error statement
          On Error GoTo errHandler:
          'hold in memory and stop screen flicker
          Application.ScreenUpdating = False
          ' Make sure we're on the right sheet
          With Sheets("Data")
          ' Get the last row used so can set up the search range
          LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          ' Set the range to search for the AB number
          Set ABrng = .Range("A1:A" & LastRow)
          ' Get the AB number from what is selected on userform2
          ABnum = txtenqup.Value
          ' Get the row of sheet for this AB number
          WriteRow = Application.Match(ABnum, ABrng, 0)
          ' Make this AB number the active cell
          With .Cells(WriteRow, 1)
          'Check for changes

          If Not hasValuePairsChanges(.Offset(0, 4).Value, cboup3.Value, _
          .Offset(0, 5).Value, cboup4.Value, _
          .Offset(0, 6).Value, cboup5.Value, _
          .Offset(0, 7).Value, cboup6.Value, _
          CDate(.Offset(0, 8).Value), Date, _
          CDbl(.Offset(0, 9).Value), CDbl(txtrev.Value), _
          .Offset(0, 12).Value, txtnotes.Value, _
          .Offset(0, 13).Value, txtdtime.Value) Then
          MsgBox "No Change in Data", vbInformation, ""
          Exit Sub
          End If

          ' Write in all the editable options
          Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
          .Offset(0, 4) = cboup3.Value
          .Offset(0, 5) = cboup4.Value
          .Offset(0, 6) = cboup5.Value
          .Offset(0, 7) = cboup6.Value
          .Offset(0, 8) = Date
          .Offset(0, 9) = txtrev.Value
          .Offset(0, 12) = txtnotes.Value
          .Offset(0, 13) = txtdtime.Value
          End With
          End With
          ' Filter the Data
          FilterMe
          ' Close the form
          Unload Me

          MsgBox ("Enquiry E0" + Me.txtenqup.Text + " has been updated")


          errHandler:
          'Protect all sheets if error occurs
          'Protect_All
          'show error information in a messagebox
          If Err.Number <> 0 Then
          MsgBox "Error " & Err.Number & " just occured."
          End If



          End Sub

          Function hasValuePairsChanges(ParamArray Args() As Variant) As Boolean
          Dim n As Long

          For n = 0 To UBound(Args) Step 2
          If Not Args(n) = Args(n + 1) Then
          hasValuePairsChanges = True
          Exit Function
          End If
          Next
          End Function





          share|improve this answer


























          • Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

            – James Hurst
            Nov 15 '18 at 13:58











          • @JamesHurst at what line did the error occur?

            – TinMan
            Nov 15 '18 at 14:00











          • ill disable the error handling

            – James Hurst
            Nov 15 '18 at 14:04











          • @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

            – TinMan
            Nov 15 '18 at 14:04











          • For n = 0 To UBound(args) Step 2

            – James Hurst
            Nov 15 '18 at 14:06














          1












          1








          1







          The easiest way would be to write a function to compare the values.



          Private Sub cmdUpdate_Click()
          ' To write edited info of userform2 to Sheets("Data")
          Dim LastRow As Long
          Dim ABnum As Double
          Dim ABrng As Range
          Dim WriteRow As Long

          'error statement
          On Error GoTo errHandler:
          'hold in memory and stop screen flicker
          Application.ScreenUpdating = False
          ' Make sure we're on the right sheet
          With Sheets("Data")
          ' Get the last row used so can set up the search range
          LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          ' Set the range to search for the AB number
          Set ABrng = .Range("A1:A" & LastRow)
          ' Get the AB number from what is selected on userform2
          ABnum = txtenqup.Value
          ' Get the row of sheet for this AB number
          WriteRow = Application.Match(ABnum, ABrng, 0)
          ' Make this AB number the active cell
          With .Cells(WriteRow, 1)
          'Check for changes

          If Not hasValuePairsChanges(.Offset(0, 4).Value, cboup3.Value, _
          .Offset(0, 5).Value, cboup4.Value, _
          .Offset(0, 6).Value, cboup5.Value, _
          .Offset(0, 7).Value, cboup6.Value, _
          CDate(.Offset(0, 8).Value), Date, _
          CDbl(.Offset(0, 9).Value), CDbl(txtrev.Value), _
          .Offset(0, 12).Value, txtnotes.Value, _
          .Offset(0, 13).Value, txtdtime.Value) Then
          MsgBox "No Change in Data", vbInformation, ""
          Exit Sub
          End If

          ' Write in all the editable options
          Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
          .Offset(0, 4) = cboup3.Value
          .Offset(0, 5) = cboup4.Value
          .Offset(0, 6) = cboup5.Value
          .Offset(0, 7) = cboup6.Value
          .Offset(0, 8) = Date
          .Offset(0, 9) = txtrev.Value
          .Offset(0, 12) = txtnotes.Value
          .Offset(0, 13) = txtdtime.Value
          End With
          End With
          ' Filter the Data
          FilterMe
          ' Close the form
          Unload Me

          MsgBox ("Enquiry E0" + Me.txtenqup.Text + " has been updated")


          errHandler:
          'Protect all sheets if error occurs
          'Protect_All
          'show error information in a messagebox
          If Err.Number <> 0 Then
          MsgBox "Error " & Err.Number & " just occured."
          End If



          End Sub

          Function hasValuePairsChanges(ParamArray Args() As Variant) As Boolean
          Dim n As Long

          For n = 0 To UBound(Args) Step 2
          If Not Args(n) = Args(n + 1) Then
          hasValuePairsChanges = True
          Exit Function
          End If
          Next
          End Function





          share|improve this answer















          The easiest way would be to write a function to compare the values.



          Private Sub cmdUpdate_Click()
          ' To write edited info of userform2 to Sheets("Data")
          Dim LastRow As Long
          Dim ABnum As Double
          Dim ABrng As Range
          Dim WriteRow As Long

          'error statement
          On Error GoTo errHandler:
          'hold in memory and stop screen flicker
          Application.ScreenUpdating = False
          ' Make sure we're on the right sheet
          With Sheets("Data")
          ' Get the last row used so can set up the search range
          LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
          ' Set the range to search for the AB number
          Set ABrng = .Range("A1:A" & LastRow)
          ' Get the AB number from what is selected on userform2
          ABnum = txtenqup.Value
          ' Get the row of sheet for this AB number
          WriteRow = Application.Match(ABnum, ABrng, 0)
          ' Make this AB number the active cell
          With .Cells(WriteRow, 1)
          'Check for changes

          If Not hasValuePairsChanges(.Offset(0, 4).Value, cboup3.Value, _
          .Offset(0, 5).Value, cboup4.Value, _
          .Offset(0, 6).Value, cboup5.Value, _
          .Offset(0, 7).Value, cboup6.Value, _
          CDate(.Offset(0, 8).Value), Date, _
          CDbl(.Offset(0, 9).Value), CDbl(txtrev.Value), _
          .Offset(0, 12).Value, txtnotes.Value, _
          .Offset(0, 13).Value, txtdtime.Value) Then
          MsgBox "No Change in Data", vbInformation, ""
          Exit Sub
          End If

          ' Write in all the editable options
          Sheets("Archive").Range("A" & Rows.Count).End(xlUp)(2).Resize(, 14).Value = .Resize(, 14).Value
          .Offset(0, 4) = cboup3.Value
          .Offset(0, 5) = cboup4.Value
          .Offset(0, 6) = cboup5.Value
          .Offset(0, 7) = cboup6.Value
          .Offset(0, 8) = Date
          .Offset(0, 9) = txtrev.Value
          .Offset(0, 12) = txtnotes.Value
          .Offset(0, 13) = txtdtime.Value
          End With
          End With
          ' Filter the Data
          FilterMe
          ' Close the form
          Unload Me

          MsgBox ("Enquiry E0" + Me.txtenqup.Text + " has been updated")


          errHandler:
          'Protect all sheets if error occurs
          'Protect_All
          'show error information in a messagebox
          If Err.Number <> 0 Then
          MsgBox "Error " & Err.Number & " just occured."
          End If



          End Sub

          Function hasValuePairsChanges(ParamArray Args() As Variant) As Boolean
          Dim n As Long

          For n = 0 To UBound(Args) Step 2
          If Not Args(n) = Args(n + 1) Then
          hasValuePairsChanges = True
          Exit Function
          End If
          Next
          End Function






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 15:15

























          answered Nov 15 '18 at 13:00









          TinManTinMan

          2,231212




          2,231212













          • Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

            – James Hurst
            Nov 15 '18 at 13:58











          • @JamesHurst at what line did the error occur?

            – TinMan
            Nov 15 '18 at 14:00











          • ill disable the error handling

            – James Hurst
            Nov 15 '18 at 14:04











          • @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

            – TinMan
            Nov 15 '18 at 14:04











          • For n = 0 To UBound(args) Step 2

            – James Hurst
            Nov 15 '18 at 14:06



















          • Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

            – James Hurst
            Nov 15 '18 at 13:58











          • @JamesHurst at what line did the error occur?

            – TinMan
            Nov 15 '18 at 14:00











          • ill disable the error handling

            – James Hurst
            Nov 15 '18 at 14:04











          • @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

            – TinMan
            Nov 15 '18 at 14:04











          • For n = 0 To UBound(args) Step 2

            – James Hurst
            Nov 15 '18 at 14:06

















          Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

          – James Hurst
          Nov 15 '18 at 13:58





          Thanks for looking at this, Ive had error 13 occur when i press the update? even if i change the data

          – James Hurst
          Nov 15 '18 at 13:58













          @JamesHurst at what line did the error occur?

          – TinMan
          Nov 15 '18 at 14:00





          @JamesHurst at what line did the error occur?

          – TinMan
          Nov 15 '18 at 14:00













          ill disable the error handling

          – James Hurst
          Nov 15 '18 at 14:04





          ill disable the error handling

          – James Hurst
          Nov 15 '18 at 14:04













          @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

          – TinMan
          Nov 15 '18 at 14:04





          @JamesHurst I made a couple of adjustments. Passing the cell values and casting .Offset(0, 8).Value to a date CDate(.Offset(0, 8).Value).

          – TinMan
          Nov 15 '18 at 14:04













          For n = 0 To UBound(args) Step 2

          – James Hurst
          Nov 15 '18 at 14:06





          For n = 0 To UBound(args) Step 2

          – James Hurst
          Nov 15 '18 at 14:06




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53319475%2fvba-userform-data-change-check%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Error while running script in elastic search , gateway timeout

          Adding quotations to stringified JSON object values