+ Reply to Thread
Results 1 to 6 of 6

Pase Special while recording a Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-10-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2007
    Posts
    5

    Pase Special while recording a Macro

    In one sheet a I have a drop down box that has options {a,b,c}. Depending on which I pick There is another sheet that does calculations based on these options. I want to create a macro that will select each option and then past the results in a new table. I have tried recording a macro selecting each option and then using paste special - values for the new table. when I run the macro each value in the table corresponds to option c. How can I make the values for a and b to be the correct value for their individual calculation?

    Thanks in advance for your help.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Pase Special while recording a Macro

    Hi,

    Could you post what you have so far and we can see if someone can help from there?

    abousetta

  3. #3
    Registered User
    Join Date
    05-10-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Pase Special while recording a Macro

    I have attached an example sheet for what I am trying to do. The top has a drop down menue with three options. Below it is the calculation that I want to perform based on the drop down selection. There is a macro button to run the macro to paste the value from each selection into the combined results table. When I run the macro it only past the results from the final selection into the table.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Pase Special while recording a Macro

    Hi

    The following is one way to do what you want.
    
    Option Explicit
    
    Sub results_macro()
    '
    ' results_macro Macro
    '
        Dim dest As Long
        dest = WorksheetFunction.Match(Range("B2"), Range("B13:B15"), 0)
        Range("B7").Copy
          
        Range("C12").Offset(dest, 0).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    End Sub
    --
    Regards
    Roger Govier
    Microsoft Excel MVP

  5. #5
    Registered User
    Join Date
    05-10-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Pase Special while recording a Macro

    Thanks for the help. That code helps for part of the issue, but I want the macro button to select each option from the drop down menue and then input the results in the combined results chart. I want to see the results for each option in the results chart while only selecting the macro button once.

    thanks in advance for your help.

  6. #6
    Valued Forum Contributor
    Join Date
    07-17-2005
    Location
    Abergavenny, Wales, UK
    MS-Off Ver
    XL2003, XL2007, XL2010, XL2013, XL2016
    Posts
    608

    Re: Pase Special while recording a Macro

    Hi

    Then use the following code
    Sub results_macro()
        Dim dest As Long, count As Long, i As Long
        count = WorksheetFunction.CountA(Range("I:I"))
        For i = 2 To count
        Range("B2") = Cells(i, "I")
            
        dest = WorksheetFunction.Match(Range("B2"), Range("B13:B15"), 0)
        Range("B7").Copy
          
        Range("C12").Offset(dest, 0).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        Next i
        
    End Sub

+ 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.6.0 RC 1