• 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.

Copy range of data from sheet to a new one

Afarag

Member
Dears,

I appreciate you help to get answering my issue,
i have a range of data from "A1:BY200" in a sheet that titled "Final" i ask to copy this range and paste it in a new sheet in considering somethings:
>: i need paste special "values and number formats" because the main data have functions that its input changes contentiously.
>: i will copy this data every day and and every one need this data migrated to a new sheet as i will use the pasted sheets as a reference after that,
>: i need the content in cell "C1" in "Final sheet" to be the New Sheet Name

Gratefully,
 

Attachments

This should work for you. Remember to change format of your workbook to .xlsm or .xlsb
Code:
Sub CopyNew()
Dim wsNew As Worksheet
Dim myRange As Range
Dim strName As String

Application.ScreenUpdating = False
With Worksheets("Final")
    'Can't use / in sheet names, changed format
    strName = Format(.Range("C1").Value, "dd-mmm-yyyy")
    Set myRange = .Range("A1:BY200")
   
    Set wsNew = ThisWorkbook.Worksheets.Add(after:=ThisWorkbook.Worksheets("Final"))
    myRange.Copy
    wsNew.Cells(1, 1).PasteSpecial xlPasteValues
    wsNew.Cells(1, 1).PasteSpecial xlPasteFormats
    wsNew.Cells(1, 1).PasteSpecial xlPasteColumnWidths
    wsNew.Name = strName
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
   
End Sub
 
@Luke M

appreciate your brilliant effort to provide me some help as i want a msg box appear when run the code in title " Are you sure to migrate the data to a new sheet?"
can we add it to your code

Cheers,
 
Hi use the below code

Code:
Sub CopyNew()
Dim wsNew As Worksheet
Dim myRange As Range
Dim strName As String
Application.ScreenUpdating = False
With Worksheets("Final")
    'Can't use / in sheet names, changed format
   strName = Format(.Range("C1").Value, "dd-mmm-yyyy")
    Set myRange = .Range("A1:BY200")
    If MsgBox("Are you sure to migrate the data to a new sheet?", vbYesNo) = vbYes Then
    Set wsNew = ThisWorkbook.Worksheets.Add(after:=ThisWorkbook.Worksheets("Final"))
    myRange.Copy
    wsNew.Cells(1, 1).PasteSpecial xlPasteValues
    wsNew.Cells(1, 1).PasteSpecial xlPasteFormats
    wsNew.Cells(1, 1).PasteSpecial xlPasteColumnWidths
    wsNew.Name = strName
Else
End If
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:
Back
Top