I want to create a command button in order to copy and paste data (based on date) from a workbook to another

jaquimdascoves

New Member
Joined
Jan 27, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I want to create a command button in order to copy and paste data from a workbook to another. I have 2 workbooks that have the same info and I want to create a button that copies the data in the red cells from workbook1 (see image)and pastes it in the green cells of workbook 2 (see image) based on the fact that the date above the green cells has to be before today´s date, if not it doesn't paste the info. For the cells that have the error #DIV/0!, i want to the green cells in workbook 2 to be blank. Cheers everyone! And thank you for any type of help!
workbook1.PNG
workbook2.PNG
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I have resolved my problem with this code code that I made for a excel similar to the format of this one:
I ended up using a normal button instead of a command button

VBA Code:
Sub Refresh()
'
' Refresh Macro
'
Dim i As Integer
 
i = 4

Workbooks.Open "Location"

While ThisWorkbook.Worksheets("Sheet1").Cells(3, i).Value <= Now()
    
        ThisWorkbook.Worksheets("Sheet1").Columns(i).Copy
        Workbooks("Workbook1").Worksheets("Sheet1").Select
        Workbooks("Workbook1").Worksheets("Sheet1").Cells(4, i).EntireColumn.Select
        'ActiveSheet.Paste
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        i = i + 1

Wend
Workbooks("Workbookx").Close SaveChanges:=True

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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