+ Reply to Thread
Results 1 to 6 of 6

Check column value in another worksheet and compare cell, and if different save data

Hybrid View

  1. #1
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Check column value in another worksheet and compare cell, and if different save data

    Hi.
    In a save button, I need to check if the column "A" worksheet called "FIN" has a value equal to the cell 'I5' worksheet called "Billet"

    Then the data will only be saved if the value of 'I5' worksheet called "Billet" do not have in column "A" worksheet called "FIN"

    and how to join the code below?
    Sub Botão6_Clique()
        Dim rCell As Range, iRow As Long
        Dim wsBoleto As Worksheet, wsFIN As Worksheet
        
        Set wsBoleto = Worksheets("Boleto")
        Set wsFIN = Worksheets("FIN")
    
        With wsFIN
            iRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        End With
        
        With wsBoleto
            For Each rCell In .Range("E16,I7,G9,G13,E19,G19")
                If IsEmpty(rCell) Then
                    MsgBox "Uma ou mais campos estão vazios, favor preencher todos os campos ...", _
                    vbInformation, "Preenchimento Obrigatório"
                    Exit Sub
                End If
            Next rCell
            .Range("L7").Value = wsFIN.Cells(iRow, 1).Offset(-1, 0).Value + 1
        End With
    
        With wsFIN
            .Cells(iRow, 1).Value = wsBoleto.Range("L7").Value
            .Cells(iRow, 2).Value = wsBoleto.Range("E16").Value
            .Cells(iRow, 3).Value = wsBoleto.Range("I7").Value
            .Cells(iRow, 4).Value = wsBoleto.Range("G11").Value
            .Cells(iRow, 5).Value = wsBoleto.Range("G9").Value
            .Cells(iRow, 6).Value = wsBoleto.Range("G13").Value
            .Cells(iRow, 7).Value = wsBoleto.Range("E19").Value
            .Cells(iRow, 8).Value = wsBoleto.Range("G19").Value
            
            MsgBox "Os dados foram salvos!!" & vbNewLine & _
                "Registro número: " & .Cells(iRow, 1).Value
        End With
        
        With wsBoleto
            .Range("E16,I7,G9,G13,E19,G19").ClearContents
        End With
    End Sub
    thank you!
    Last edited by marreco; 09-21-2012 at 08:00 PM.
    "No xadrez nem sempre a menor dist?ncia entre dois pontos ? uma linha reta" G. Kasparov.

    If your problem is solved, please say so clearly, and mark your thread as Solved: Click the Edit button on your first post in the thread, Click Go Advanced, select b from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Edit button will not appear -- ask a moderator to mark it.

  2. #2
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Check column value in another worksheet and compare cell, and if different save data

    Hi.

    any idea?

    Thank you!!!

  3. #3
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Check column value in another worksheet and compare cell, and if different save data

    Hi.

    any idea?

    Thank you!!!

  4. #4
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Check column value in another worksheet and compare cell, and if different save data

    Hi.

    any idea?

    Thank you!!!

  5. #5
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Check column value in another worksheet and compare cell, and if different save data

    You could use the following - if Value in Worksheet Boleto I5 not in Worksheet Fin Column A then save workbook
    
    Sub Botão6_Clique()
        Dim rCell As Range, iRow As Long, fnRng As Range
        Dim wsBoleto As Worksheet, wsFIN As Worksheet
        
        Set wsBoleto = Worksheets("Boleto")
        Set wsFIN = Worksheets("FIN")
    
        With wsFIN
            iRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        End With
        
        With wsBoleto
            For Each rCell In .Range("E16,I7,G9,G13,E19,G19")
                If IsEmpty(rCell) Then
                    MsgBox "Uma ou mais campos estão vazios, favor preencher todos os campos ...", _
                    vbInformation, "Preenchimento Obrigatório"
                    Exit Sub
                End If
            Next rCell
            .Range("L7").Value = wsFIN.Cells(iRow, 1).Offset(-1, 0).Value + 1
        End With
    
        With wsFIN
            .Cells(iRow, 1).Value = wsBoleto.Range("L7").Value
            .Cells(iRow, 2).Value = wsBoleto.Range("E16").Value
            .Cells(iRow, 3).Value = wsBoleto.Range("I7").Value
            .Cells(iRow, 4).Value = wsBoleto.Range("G11").Value
            .Cells(iRow, 5).Value = wsBoleto.Range("G9").Value
            .Cells(iRow, 6).Value = wsBoleto.Range("G13").Value
            .Cells(iRow, 7).Value = wsBoleto.Range("E19").Value
            .Cells(iRow, 8).Value = wsBoleto.Range("G19").Value
            
            MsgBox "Os dados foram salvos!!" & vbNewLine & _
                "Registro número: " & .Cells(iRow, 1).Value
        End With
        
        With wsBoleto
            .Range("E16,I7,G9,G13,E19,G19").ClearContents
        End With
    'Additional code to check condition to save
    Set fnRng = wsFIN.Columns(1).Find(wsBoleto.Range("I5"), wsFIN.Cells(1, 1), xlValues, xlWhole)
    If Not fnRng Is Nothing Then
    'value is present
    'you could exit sub
    Exit Sub
    Else
    'Value not present
    ActiveWorkbook.Save
    End If
    End Sub
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  6. #6
    Valued Forum Contributor marreco's Avatar
    Join Date
    07-02-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2010
    Posts
    1,862

    Re: Check column value in another worksheet and compare cell, and if different save data

    It was great!!

    I am very happy with your help!

    thank you very much!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1