Create new Workbook from exist

KreshBell

New Member
Joined
Jan 13, 2022
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi,
please, can someone make me a macro that would do this.
I would like to generate a new xlsx file by double-clicking on define cell in a row, which would place certain cells from this row in a new file.

For example, after double-clicking on cell E7 *or select and run macro), I would like to generate a new xlsx file that will place cells from that row in column F7, K7, L7, BB7, BC7 AND BG7 into a new file in this way
excel1.png


E7 TO A1, F7 TO A2, K7 TO A3, L7 TO A4, BB7 TO A5, BC7 TO A6 AND BG7 TO A7 *always to A column)
excel2.png



I would also like to be able to choose the location to save the new file after running the macro
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
It is hard to work with a picture. It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach a screenshot (not a picture) of your sheet. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. (de-sensitized if necessary).
 
Upvote 0
Hi,
please, can someone make me a macro that would do this.
I would like to generate a new xlsx file by double-clicking on define cell in a row, which would place certain cells from this row in a new file.

For example, after double-clicking on cell E7 *or select and run macro), I would like to generate a new xlsx file that will place cells from that row in column F7, K7, L7, BB7, BC7 AND BG7 into a new file in this way
View attachment 117884

E7 TO A1, F7 TO A2, K7 TO A3, L7 TO A4, BB7 TO A5, BC7 TO A6 AND BG7 TO A7 *always to A column)
View attachment 117885


I would also like to be able to choose the location to save the new file after running the macro
Does this work as you want it to.

It works when a cell is selected.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim arr() As Variant
Dim varFileName As Variant
Dim Ws As Worksheet

  i = Target.Row

  Set Ws = ActiveSheet
  
  Workbooks.Add
  
  ' Transpose an array of the required values to the new workbook.
  ActiveSheet.Range("A1:A7").Value = Application.Transpose(Array(Ws.Range("E" & i).Value, Ws.Range("F" & i).Value, Ws.Range("K" & i).Value, _
    Ws.Range("L" & i).Value, Ws.Range("BB" & i).Value, Ws.Range("BC" & i).Value, Ws.Range("BG" & i).Value))

  ' Displaying the saveas dialog box.
   varFileName = Application.GetSaveAsFilename("", "Excel files,*.xlsx", 1, "Select your folder and filename")

  ' User didn't save the file.
  If TypeName(varFileName) = "Boolean" Then
    ActiveWorkbook.Close False
    Exit Sub
  End If

  ' Save the workbook.
  ActiveWorkbook.SaveAs varFileName

End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Create new xlsx file
and: Create new xlsx file with macro

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
I have an excel sheet with many rows. I would like that when I select the first cell in the row and then start the macro, I get a new file that will pick up certain values from the selected row and always place them in the first column of the new file.
For example.
Source file
Source.png



If I select cell A7 in the file Source File and run the macro, it generates the file Target File A
Target A.png



If I select cell A9 in the file Source File and run the macro, it generates the file Target File B
Target B.png
 
Upvote 0
source file
P1103_0408_06WO00004420_M001Train Car 2 - Fixed Dining Table100NO12Stephen Archer4541345427
P1103_0408_07WO00004363_M001Train Car 2 - Banquette Seats100NO24Stephen Archer4541345427
P1103_0408_08WO00004421_M001Train Car 2 - Decorative Dividers100NO6Stephen Archer4541345427
P1103_0408_09Train Car 2 - Themed AccessoriesN/ANO12Stephen Archer4541345427
P1103_0408_10Train Car 2 - Window TreatmentsN/ANO8Stephen Archer4541345427
P1103_0408_11WO00005232_M001Train car 2 - Train car Façade 100NO1Stephen Archer4541345427
P1103_0408_12WO00005233_M001Train car 2 - Window Box internal 100NO8Stephen Archer4541345427
P1103_0408_13WO00005234_M001Train car 2 - Window Box External side100NO4Stephen Archer4541345427
P1103_0408_14WO00006246_M001Train car 2 - Window Box Ends100NO4Stephen Archer4546445478
P1103_0408_15Train Car 2 - Decorative Ballustrade 100NO1Stephen Archer4541345427
P1103_0408_16WO00005237_M001Train Car 2 - Banquette Seats removable ADA100NO1Stephen Archer4541345427
P1103_0408_17WO00006722_M001Train Car 1 - In service works window drapery90NO8Stephen Archer4552745541


Target file A
P1103_0408_12
WO00005233_M001
Train car 2 - Window Box internal
NO
8
45413
45427


Target file B
P1103_0408_14
WO00006246_M001
Train car 2 - Window Box Ends
NO
4
45464
45478
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

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