Copy Range and Input Copied Cells into a different workbook.

finAnalysis

New Member
Joined
Oct 13, 2021
Messages
12
Office Version
  1. 365
Platform
  1. Windows
This code selects the range to copy from, and then attempts to insert the copied cells into a new defined range. I am having issues with the code and getting errors. Any help is appreciated.

VBA Code:
Sub Rom_Copy()

Dim Rom_Copy As Variant
Dim CopyFromRange As Range
Dim PasteToRange As Range

MsgBox ("Select ROM")

Rom_Copy = Application.GetOpenFilename(FileFilter:="Excel Files,*.xl*;*.xm*")
If Rom_Copy <> False Then
    ActiveWorkbook.ActiveSheet.Select
    'Will not pick specific sheet, will need to do it myself when range is selected'
    On Error Resume Next
    Set CopyFromRange = Application.InputBox(Prompt:="Select a range to copy from", Title:="Range Selection", Default:=ActiveCell.Address, Type:=8)
    If CopyFromRange Is Nothing Then Exit Sub
    On Error GoTo 0
   
    On Error Resume Next
    Set PasteToRange = Application.InputBox(Prompt:="Select a range to paste to", Title:="Range Selection", Default:=ActiveCell.Address, Type:=8)
    If PasteToRange Is Nothing Then Exit Sub
    On Error GoTo 0
 
    CopyFromRange.Copy
    Selection.Insert Shift:=xlDown
 
    PasteToRange.Cells(1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
End If
 
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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