Results 1 to 6 of 6

Macro to Copy Data and Paste Values Based on cell criteria

Threaded View

Taislin Macro to Copy Data and Paste... 11-16-2012, 05:14 PM
tigeravatar Re: Macro to Copy Data and... 11-16-2012, 05:58 PM
Taislin Re: Macro to Copy Data and... 11-16-2012, 06:13 PM
Taislin Re: Macro to Copy Data and... 11-16-2012, 06:23 PM
tigeravatar Re: Macro to Copy Data and... 11-16-2012, 06:47 PM
Taislin Re: Macro to Copy Data and... 11-16-2012, 06:51 PM
  1. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Macro to Copy Data and Paste Values Based on cell criteria

    Taislin,

    Attached is a modified version of your posted workbook.
    First, I had to get rid of all of the merged cells. They are a nightmare to work with, and it is quite easy to get the effect without actually using merged cells. You can select the "merge area" and right-click -> alignment -> for Horizontal select "Center Across Selection" -> OK

    So, now that there are no longer merged cells to deal with, the code is pretty straightfoward. I assigned the below code to the Go "button" on the 'Menu' sheet:
    Sub Go_Click()
        
        Dim rngCopy As Range
        Dim strDay As String
        Dim strMkt As String
        
        If Len(Range("C7").Value) = 0 Then
            Range("C7").MergeArea.Select
            MsgBox "Must select the DAY you want", , "Missing Day"
            Exit Sub
        Else
            strDay = Range("C7").Value
        End If
        
        If Len(Range("F7").Value) = 0 Then
            Range("F7").MergeArea.Select
            MsgBox "Must selec tthe MARKET you want", , "Missing Market"
            Exit Sub
        Else
            strMkt = Range("F7").Value
        End If
        
        Application.ScreenUpdating = False
        With Sheets(strDay)
            Set rngCopy = .Rows(1).Find(strMkt).Resize(, 5)
            Set rngCopy = Range(rngCopy, .Cells(.Rows.Count, rngCopy.Column).End(xlUp))
        End With
        
        With Sheets("REPORT")
            .Range("C17:G" & Rows.Count).Clear
            rngCopy.Copy
            With .Range("C17")
                .PasteSpecial xlPasteValues
                .PasteSpecial xlPasteFormats
                Application.CutCopyMode = False
            End With
            .Select
            .Range("C17").End(xlDown).Offset(1).Select
        End With
        Application.ScreenUpdating = True
        
    End Sub


    [EDIT]:
    Also, you had a typo on your market drop-down selection. It needed to be "FOOTBALL - MATCH ODDS" but you had "FOOTBALL -MATCH ODDS" (it was missing a space after the dash). Made that quick change and it worked just fine for that market.
    Attached Files Attached Files
    Last edited by tigeravatar; 11-16-2012 at 06:01 PM. Reason: added edit note
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

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