I have the following code to open a specific sheet based on cell value, but won't paste data.

J15491

New Member
Joined
Jan 10, 2020
Messages
34
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I need help. I want to be able to copy data from a table in worksheet1(Register) to another worksheet (either "rent" or "utilities" based on the value in cell I14. My code opens the appropriate worksheet, but I can't seem to get the data to copy to cells in the destination worksheet. I have multiple cells to copy and too. I also want to print two copies after the data is pasted. Any assistance will be appreciated.
.

Sub CopyDataRent()
'Copy the data
If Range("I14") = "Rent" Then
Sheets("Rent").Select
Sheets("Rent").Name = "Rent"
Range("E11").Copy
'Select the target range
Range("B11").Select
'Paste in the target destination
ActiveSheet.Paste

Application.CutCopyMode = False

End If

End Sub

Sub CopyDataUtilities()
'Copy the data
If Range("I14") = "Utilities" Then
Sheets("Utilities").Select
Sheets("Utilities").Name = "Utilities"
Range("E11").Copy
'Select the target range
Range("B11").Select
'Paste in the target destination
ActiveSheet.Paste

Application.CutCopyMode = False

End If

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
may I ask why VBA?
in o365 there is a =filter() function whichcan do tons of amazing stuff.

but if you insist on copying in vba for some reason then follow this example:

when copying data in VBA try using advanced filter since its the fastest way.
he explains how this work better then perfectly.

also a side note
currently in o365 you have such extreme capabilities that what was needed tobe done in vba in 2016 or earlier now can be done by formulas, Power query, DAX Lambda function or Let function.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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