PasteSpecial - Defining a range that is variable...?

VBAMePlease

Board Regular
Joined
Jun 19, 2017
Messages
59
New- and by new I mean virgin-new - to VBA on Excel; with that in mind sorry if this seems excruciatingly easy.

I'm utilizing a Copy & Paste VBA that runs on an ActiveX Command Button.

When executed, it copies information from C18:C123 and pastes it into a column (H17:BY17) that matches the header for C17. It currently pastes the formulas, and I need it to paste values and source formatting.

Here is the current code I am running with:

Code:
Private Sub Dashboard_Base_Case_Update_Button_Click()


Set lookup_rng = Range("H17:BY17")


For Each cell In lookup_rng
    If cell.Value = Range("C17").Value Then
        Range("C18:C123").Copy
        cell.Offset(1, 0).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
    End If
Next cell




End Sub

Do I need to assign the lookup value a range name and then .pastespecial from there? At a loss and would appreciate the help.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Try:
Code:
If cell.Value = Range("C17").Value Then
        Range("C18:C123").Copy
        cell.Offset(1, 0).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    End If
 
Upvote 0
I need it to paste values and source formatting.


Untested...

Code:
Private Sub Dashboard_Base_Case_Update_Button_Click()
    Set lookup_rng = Range("H17:BY17")
    For Each cell In lookup_rng
        If cell.Value = Range("C17").Value Then
            Range("C18:C123").Copy
            With cell.Offset(1, 0)
                .PasteSpecial Paste:=xlPasteValues
                .PasteSpecial Paste:=xlPasteFormats
            End With
            Application.CutCopyMode = False
        End If
    Next cell
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,592
Messages
6,125,713
Members
449,253
Latest member
Mbogo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top