+ Reply to Thread
Results 1 to 7 of 7

Need to add data to table in result sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    176

    Need to add data to table in result sheets

    Hi,

    I have data in table format in sheet1 but when I run the below code its not copying the result data in table format (in received sheet). Could any one please have a look and help me?

    Thanks in advance for your help!!

    
    Sub copy_data()
      
      p = InputBox("Please enter date", "Enter Start Date")
      q = InputBox("Please enter date", "Enter End Date")
      
      Application.ScreenUpdating = False
      With Sheets("Sheet1")
        If Not Evaluate("ISREF('Received'!A1)") Then
          Sheets.Add(After:=Sheets("Sheet1")).Name = "Received"
        Else
          Sheets("Received").UsedRange.ClearContents
        End If
        
        .Rows(1).Copy Sheets("Received").Rows(1)
    
        On Error Resume Next
    
        With .UsedRange
          .AutoFilter 12, ">" & CLng(CDate(p & " 23:59")), xlAnd, "<" & CLng(CDate(q & " 00:00"))
          .Offset(1).Copy Sheets("Received").Cells(2, 1)
          .AutoFilter
    
      End With
      
       Sheets("Received").Columns.AutoFit
    
      Application.ScreenUpdating = True
    End Sub
    Regards,
    Humac
    Last edited by humacdeep; 02-20-2012 at 05:58 PM. Reason: Solved

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Need to add data to table in result sheets

    hi Humac, can you post file in question?

  3. #3
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    176

    Re: Need to add data to table in result sheets

    Hi Watersev,

    I have attached the file.

    The below code is adding the result sheet to table but I am unable to make it dynamic. Please help.

    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$W$591"), , xlYes).Name = _
            "Table2"
    Regards,
    Humac
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Need to add data to table in result sheets

    try this:

    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$W$" & Cells(Rows.Count, 1).End(xlUp).Row), , xlYes).Name = "Table2"
    PS. Not tested

  5. #5
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    176

    Re: Need to add data to table in result sheets

    It is working if I delete the existing Received Sheet and run the Macro and its not working when I try to run the macro with out deleting the existng sheet .

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Need to add data to table in result sheets

    try this:

    Sub test()
    
    With Sheets("Received")
        
        .ListObjects.Add(, .Range("$A$1:$W$" & .Cells(Rows.Count, 1).End(xlUp).Row), , xlYes).Name = "Table2"
    
    End With
    
    End Sub
    Run code "test"
    Attached Files Attached Files
    Last edited by watersev; 02-20-2012 at 05:38 PM.

  7. #7
    Forum Contributor
    Join Date
    09-10-2011
    Location
    Chicago
    MS-Off Ver
    Excel 2007
    Posts
    176

    Re: Need to add data to table in result sheets

    Thanks a LOT Watersev... its working

+ 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