Copying data into new sheet depending upon selection of rows or columns based upon highlighted [closed]

StackOverflow https://stackoverflow.com/questions/11471592

  •  20-06-2021
  •  | 
  •  

Domanda

This question may be posted on other forums as well but i am unable to find out my answer.

I want a macro that could

  • Copy my selected rows or columns or cells.
  • makes new file.xlsx
  • pastes that data in that sheet.
È stato utile?

Soluzione

Are you looking to paste it into a certain place or just the start of the sheet? What would determine whether you copy the row or column?

This will copy the row of your currently selected cell and then paste it into the first row of a new workbook

Sub CopyRow()
  Selection.EntireRow.Copy
  Workbooks.Add
  ActiveSheet.Paste
End Sub

Edit

Add this code to ask if you want to save, you could then have a question to copy row or column or have a separate macro to copy the column.

Dim docname As String
If MsgBox("Would you like to save the doc?", vbYesNo, "Save?") = vbYes Then
 docname = InputBox("What would you like to call the doc?", "Title")
 ActiveWorkbook.SaveAs Filename:=docname, FileFormat:=xlOpenXMLWorkbook
End If
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top