+ Reply to Thread
Results 1 to 3 of 3

Copy Data from one Sheet to Another Sheet including comment and formats

  1. #1
    Registered User
    Join Date
    03-23-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Copy Data from one Sheet to Another Sheet including comment and formats

    Hi All
    I have Trying to copy data from one sheet to multiple sheet with comments and cell format. I wrote the below code. It copies only data to different sheet but not copying the comment i have supplied to specific cells and not hiding specified columns. Please help me on this Issue.

    Thanks in Advance
    Sub CREATESHEET()
    Dim MainSheet As Worksheet
    Dim TempSheet As Worksheet
    Dim TargetSheet As Worksheet
    Dim MyRange As Range
    Dim ColHeading As Range
    Dim ListRange As Range
    Dim TempRange As Range
    Dim TempCell As Range

    Set MainSheet = Worksheets("ALL")
    'MsgBox MainSheet.Range("A1").Value
    Set TempSheet = Worksheets.Add

    With MainSheet
    Set MyRange = .UsedRange
    Set ColHeading = .Range("A1", .Cells.SpecialCells(xlCellTypeLastCell))

    Intersect(ColHeading, .Columns("C")).AdvancedFilter _
    Action:=xlFilterCopy, _
    CopyToRange:=TempSheet.Range("A1"), _
    Unique:=True

    TempSheet.Range("D1").Value = TempSheet.Range("A1").Value
    End With

    With TempSheet
    Set ListRange = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
    End With

    For Each TempCell In ListRange.Cells
    MsgBox TempCell.Value
    If SHEETEXIST(TempCell.Value) = False Then
    Set TargetSheet = Sheets.Add
    On Error Resume Next
    TargetSheet.Name = TempCell.Value
    TargetSheet.Move after:=Sheets(Sheets.Count)
    Else
    Set TargetSheet = Worksheets(TempCell.Value)
    TargetSheet.Cells.Clear
    TargetSheet.Cells.ClearComments
    End If

    TempSheet.Range("D2").Value = "=" & Chr(34) & "=" & TempCell.Value & Chr(34)
    'MainSheet.Rows("1:1").Copy Destination:=TargetSheet.Range("A1")
    ColHeading.AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=TempSheet.Range("D1:D2"), _
    CopyToRange:=TargetSheet.Range("A1"), _
    Unique:=False
    Next TempCell
    Application.DisplayAlerts = False
    TempSheet.Delete
    'MainSheet.Save

    End Sub
    Function SHEETEXIST(WksName As String) As Boolean
    On Error Resume Next
    SHEETEXIST = CBool(Len(Worksheets(WksName).Name) > 0)

    End Function

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Copy Data from one Sheet to Another Sheet including comment and formats

    why such elaborate macro

    if I understand you correctly why not a simple macro like this (modify to suit you)
    myrage(in sheet 2) source. resultrange(sheet1) is the top left cell from which the source range is to be copied value comments and format

    Please Login or Register  to view this content.
    I am not an expert. better solutions may be available
    $$$$venkat1926$$$$@gmail.com

  3. #3
    Registered User
    Join Date
    03-23-2012
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Copy Data from one Sheet to Another Sheet including comment and formats

    hi venkat
    I think u not understood my problem, For reference I put a Dummy Sheet. Please go through the sheet, if u have any idea suggest me.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1