VBA button to paste values in cells based on the contents of another cell

povictory

New Member
Joined
May 28, 2015
Messages
41
Hello,

I don't know if this is even possible, but thought I'd ask!

I have a budget file with some formulas pulling from another sheet for each month. I have a drop down menu cell (B2 in example) that corresponds to the monthly columns in the sheet (D5:O5). What I would like to do is have a button linked to VBA code that would copy/paste values of the yellow highlighted cells in row 6:8 that correspond to the column in the drop down menu cell B2. For example, since Apr20 is in the drop down cell in this example, when I click the button, I would like it to copy and paste the values in cells G6:G8, replacing the formulas that were there before.

Is this even possible? Any advice or ideas would be appreciated.

Thanks!
 

Attachments

  • Capture.JPG
    Capture.JPG
    62.5 KB · Views: 17

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Is this doing what you wanted?

VBA Code:
Sub PasteValues()

Dim colnum As Long
Dim monthname As String

monthname = Range("B2")

colnum = 4
Do Until Cells(5, colnum) = monthname
colnum = colnum + 1
Loop

Range(Cells(6, colnum), Cells(8, colnum)).Copy
Range(Cells(6, colnum), Cells(8, colnum)).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("B2").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

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