How do I get Excel to copy a range of cells into another cell?

DreyFox

Board Regular
Joined
Nov 25, 2020
Messages
61
Office Version
  1. 2016
Platform
  1. Windows
Hello!

This is the functionality I would like. First the user clicks a command button, which will let them name the sheet that they will create, then copy a certain range of the current sheet into the new sheet keeping its formatting. What I have tried (code):
VBA Code:
Private Sub CommandButton1_Click()
Dim val As String

val = InputBox("Enter the configuration name for the current selection")

Sheets.Add(After:=Sheets(Sheets.Count)).Name = val

Worksheets("Feed Configurator").Range("A108:M109").Copy Worksheets(val)

End Sub
It unfortunately does not work. Any help or assistance would be greatly appreciated! Thank you!
 
Is there a way to keep the formatting when doing this? For example I'd like cells that were merged to stay merged when they're copied over

Any help is greatly appreciated!
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Best advice is. Do not used merged cells, they are an abomination & should be avoided like the plague.
 
Upvote 0
Okay thank you! Is there a reason why? Do they mess with VBA?
 
Upvote 0
VBA does not like merged cells, if you use them you will be continually having to find workrounds to get things working.
Also they can cause problems with filtering & sorting.
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,794
Members
449,468
Latest member
AGreen17

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