help with writing code efficiently

maverick93

New Member
Joined
Jan 7, 2010
Messages
23
I have two worksheets and using a command button I would like to make all of the values the cells of ActiveSheet.range("D1:K40") = the values in Sheets("2").Range("D1:K40"). The problem is that when i do this nothing happens however if do it for an individual cell it works.

I guess what I'm asking is there an efficient way to write the code so that each of the cells in Range("D1:K40")

I can't use the cut an paste method because there are merged cells in one sheet and the formatting isn't exactly the same.

VBA Code:
Private Sub CommandButton1_Click()

ActiveSheet.Range("D1") = Sheets("2").Range("D1")
ActiveSheet.Range("E1") = Sheets("2").Range("E1")
ActiveSheet.Range("F1") = Sheets("2").Range("D1")
...
ActiveSheet.Range("D2") = Sheets("2").Range("D2")
ActiveSheet.Range("E2") = Sheets("2").Range("E2")
ActiveSheet.Range("F2") = Sheets("2").Range("D2")

End Sub

Thanks for any help
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
hi,
try

VBA Code:
Private Sub CommandButton1_Click()

    Sheets("2").Range("D1:K40").Copy ActiveSheet.Range("D1")


End Sub

this however, copies everything
Dave
 
Upvote 0
This is friendly welcoming site supported by volunteers to provide assistance to anyone having difficulty with Excel, VBA etc regardless of their ability - poking fun I think I can say, would not be expected from any contributor.

Glad you found a resolution for your requirement – we appreciated the feedback.

Dave
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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