I am a newbie to Excel VBA
.
I am trying to copy a range of data from worksheet output into a new excel workbook and save the new workbook with the the value in E3.
As a bonus, I would love to be able to also copy the data into wordpad
and save as E3.xml
Here is the VBA
I have thus far:
Sub CopyOutput()
Dim myname As String
mystring = E3
Dim myselection As Range
myselection = Sheets("Output").Columns("F").Select
Set NewBook = Workbooks.Add
With NewBook
.SaveAs Filename:="C:\Program Files\White Plume\Scenarios\" & myname & ".xls", FileFormat:= _
xlsx, CreateBackup:=False
End With
myselection.Paste
End Sub
Copy a Cell or Range to Another Worksheet First, define the range or the cell that you want to copy. Next, type a dot (.) and select the copy method from the list of properties and methods. Here you'll get an intellisense to define the destination of the cell copied.
Copy VBA method is to copy a particular range. When you copy a range of cells manually by, for example, using the “Ctrl + C” keyboard shortcut, the range of cells is copied to the Clipboard. You can use the Range. Copy method to achieve the same thing.
Open both the workbook that contains the macro you want to copy, and the workbook where you want to copy it. On the Developer tab, click Visual Basic to open the Visual Basic Editor. , or press CTRL+R . In the Project Explorer pane, drag the module containing the macro you want to copy to the destination workbook.
Copy all the data on the sheet by pressing CTRL+C. Open the workbook in which you want to paste the data, then click the + in the status bar to add a new blank worksheet. Click the first cell in the new worksheet, then press CTRL+V to paste the data into that worksheet.
Modify to suit your specifics, or make more generic as needed:
Private Sub CopyItOver()
Set NewBook = Workbooks.Add
Workbooks("Whatever.xlsx").Worksheets("output").Range("A1:K10").Copy
NewBook.Worksheets("Sheet1").Range("A1").PasteSpecial (xlPasteValues)
NewBook.SaveAs FileName:=NewBook.Worksheets("Sheet1").Range("E3").Value
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With