+ Reply to Thread
Results 1 to 3 of 3

Thread: C&P Cell Values From One Worksheet to Second Worksheet Conditionally

  1. #1
    Registered User
    Join Date
    08-06-2011
    Location
    Dayton, OH
    MS-Off Ver
    Excel 2003
    Posts
    4

    Smile C&P Cell Values From One Worksheet to Second Worksheet Conditionally

    I am working on a project for my job. I am extremely new at VBA but I am a "learn-you-go" type. Here is what I am trying to do:

    Worksheet 1 is named "Daily Work" and contains 10 (A-J) columns of data and an unspecified number of rows. The only information relevant to Worksheet 2 is located in Rows A and B. Row A has a header of "DBCode" and Row B has a header of "Loan #" located in cells A1 and B1, respectively. The data in Column A are a combination of UpperCase letters and Numbers (some examples are: FAILHP, PHNHLD, 2NDEQA, and FC104). The data in Column B are all 10 digit numbers.

    I need the Macro to look at the worksheet "Daily Work" and if the value a cell in Column A is "FC104", then I want the value of the cell in Column B to be copies and pasted into Worksheet 2.

    Worksheet 2 is named "Audit" and contains one column of data (Column A). This column has a header of "Loan #" and the cells below that header should be populated with the data copied and pasted from "Daily Work" by the Macro.

    Further, if it is possible, I would like the Macro to paste the copied value from "Daily Work" to the first blank cell in Column A in "Audit".

    Now, just so you know that I am not "mooching" off your expertise, I will post the code that I tried. I am aware that it doesn't work, but I figured you could enjoy a laugh.

        
    Sub Macro1()
    
        Dim loannum As Range
        Dim dbcode As Range
        Dim wDaily As Worksheet
        Dim cell As Range
        Dim myRng As Range
        Dim cRow As Row
        
        Daily = Sheets("Daily Work").Name
        audit = Sheets("Audit").Name
        Range("A1:A50") = strCode
        cRow = Row.Active
        
            Set wDaily = ActiveWorksheet
            For Each Row In wDaily.Range("A1:B50")
                If cRow.Value = "FC104" Then
                    Selection.Offset(0, 1).Select
                    Selection.Copy
                    Sheets("Audit").Select
                        If Cells("A2") = Empty Then
                            Cells("A2").PasteSpecial xlPasteAll
                        Else
                        Do Until ActiveCell = Empty
                            ActiveCell.Offset(1, 0).Select
                            Loop
                            ActiveCell.PasteSpecial xlPasteAll
                        End If
                    Sheets("Daily Work").Select
                Else
                End If
            Next objLoan
        
    End Sub
    Last edited by Ishness; 08-08-2011 at 09:17 AM. Reason: Issue has been solved.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: C&P Cell Values From One Worksheet to Second Worksheet Conditionally

    This should do it:

    Option Explicit
    
    Sub AuditTransfer()
    Dim wsDaily As Worksheet
    Dim wsAudit As Worksheet
    Dim strCode As String
    Dim cFIND As Range
    Dim cFIRST As Range
    
    strCode = Application.InputBox("Code to find and transfer?", "Code Search", "FC104", Type:=2)
    If strCode = "False" Then Exit Sub
    
    Set wsDaily = ThisWorkbook.Sheets("Daily Work")
    Set wsAudit = ThisWorkbook.Sheets("Audit")
    
    Set cFIND = wsDaily.Range("A:B").Find(strCode, LookIn:=xlValues, Lookat:=xlWhole)
    If Not cFIND Is Nothing Then
        Set cFIRST = cFIND
        Do
            wsAudit.Range("A" & wsAudit.Rows.Count).End(xlUp).Offset(1).Value = cFIND.Offset(, 1).Value
            Set cFIND = wsDaily.Range("A:B").FindNext(cFIND)
        Loop Until cFIND.Address = cFIRST.Address
    Else
        MsgBox "The code '" & strCode & "' was not found."
    End If
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    08-06-2011
    Location
    Dayton, OH
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: C&P Cell Values From One Worksheet to Second Worksheet Conditionally

    Thank you so very much. This works like a charm! I never thought to use an Input Box. Further, I am able to learn from your example, and have started to better understand where I went wrong. Again, 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)

Tags for this Thread

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.2.0