C/P to range based on criteria. Need Help

Sleeplol

Board Regular
Joined
Apr 10, 2019
Messages
194
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

I'm attempting to Copy Paste (Values Only) from Sheet1 to Sheet2 based on criteria in Sheet1 Z4 & AA4 dropdowns:
(Not an event change; just a macro I'll attach to a button after the selections is made)
1666977363611.png

For instance, if 2022 May is selected, then we could paste Sheet1.Range("Z11:BF50") to Sheet2 Column C that is to the right of the corresponding value.
In this case it would paste to C161.
Also, it would be great if it would always write over the data in those ranges, for instance: User makes an additional change for 2022 May and wants to update Sheet2 again, the new values write over the previous values in that specific range.

1666977258656.png


Also, would there be a way to recall the saved data from Sheet2 back to Sheet1?
For instance 2022 May is selected in Sheet1, the macro then grabs the data from Sheet2 (in this case) C161:AI200 and pastes those Values (only values) back to Sheet1.Range("Z11:BF50")??? (it is always this range in Sheet1.

I would appreciate any help with this; thanks
 

Attachments

  • 1666976893775.png
    1666976893775.png
    1.5 KB · Views: 1
  • 1666977253126.png
    1666977253126.png
    12.9 KB · Views: 2

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Update and break down:

Update
In Sheet 1 I'll combine values Z4 and AA4 for a single criteria cell; I'll use AA1
In Sheet 2 I'll combine the values for columns A & B and put them in C

Now for the Logic break down
Step 1: Find AA1 value in Sheet2 column C
Step 2: Activate the cell offset(0,1)
Step 3: Paste Sheet1.Range("Z11:BF50") into that offset cell

Below is what I came up with. A bit rough but it works. Maybe it'll be useful for someone down the road.
Any of you wizards are welcome to clean this up and I'll happily switch my script for yours LOL

VBA Code:
Sub FindThenPaste()
rngY = Worksheets("Sheet1").Range("AA4").Value

    Sheets("Sheet2").Select
    Columns("C:C").Select
    Selection.find(What:=rngY, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
      
ActiveCell.Select


Call PasteOffsetOS

Worksheets("Sheet1").Activate

End Sub

Sub PasteOffsetOS()

Worksheets("Sheet1").Range("Z11:BF50").Copy
ActiveCell.Offset(0, 1).PasteSpecial xlPasteFormats
ActiveCell.Offset(0, 1).PasteSpecial xlPasteValues

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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