• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Create new xlsx file

KreshBell

New Member
Cross post w/o links
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
1728462051453.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)
1728462934305.png

I would also like to be able to choose the location to save the new file after running the macro
 
Hi KreshBell,
here is my attempt, paste it into the worksheet module (not a standard module), you can double-click any cell in the desired row.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'https://chandoo.org/forum/threads/create-new-xlsx-file.57812/
    
    Dim arr         As Variant
    Dim TargArr     As Range
    Dim newWbk      As Workbook
    Dim myPath      As String
    
    Cancel = True
    
    Application.ScreenUpdating = False
    
    arr = Array(Me.Cells(Target.Row, 5).Value, Me.Cells(Target.Row, 6).Value, Me.Cells(Target.Row, 11).Value, _
          Me.Cells(Target.Row, 12).Value, Me.Cells(Target.Row, 54).Value, Me.Cells(Target.Row, 55).Value, Me.Cells(Target.Row, 59).Value)
    
    Set newWbk = Workbooks.Add
    Set TargArr = newWbk.Sheets(1).Range("A1:A7")
    TargArr.Value = Application.Transpose(arr)
    
    myPath = Application.GetSaveAsFilename( _
             FileFilter:="Excel workbook(*.xlsx), *.xlsx", _
             Title:="Choose .....")
    
    If myPath <> "False" Then
        
        newWbk.SaveAs Filename:=myPath, FileFormat:=xlOpenXMLWorkbook
        
    Else
        '
        newWbk.Close False
    End If
    
End Sub
 
Back
Top