Results 1 to 3 of 3

Power Query tables in VBA

Threaded View

  1. #3
    Forum Contributor
    Join Date
    11-01-2016
    Location
    Prague
    MS-Off Ver
    2013
    Posts
    121

    Re: Power Query tables in VBA

    Quote Originally Posted by Norie View Post
    Orhan

    This works for me to select the header row of a table generated with Power Query.
    Dim tbl As ListObject
    
        Set tbl = Sheet2.ListObjects("Table_0")
        
        tbl.HeaderRowRange.Select
    Thank you Norie. But unfortunately, it didnt help still. I am sharing my all code below. Maybe if I kindly ask to review it, you can find the cause ?

    Basically, I have two range as header and source. And I am pointing for header the Range(Cells(1,1)) and for source I am pointing Range(Cell(2,1)), but some how VBA is pasting second row as header to the new file

    And if I change my Sheet1 with a non-table data. It is working. But I need to adjust this for table, since my source will be a power query.

    ActiveWorkbook.Sheets(1).Activate
            
        lastrow = Sheets(1).UsedRange.Rows.Count
        lastColumn = 8
        With Sheets(1)
            .Range(Cells(1, 1), Cells(lastrow, lastColumn)).Select
            Set overtimes = Selection
            overtimes.Sort Key1:=Range("H2"), Order1:=xlAscending
        End With
        With Sheets(1)
            .Range(Cells(1, 1), Cells(1, lastColumn)).Select
            Set header = Selection.SpecialCells(xlCellTypeVisible)
        End With
        With Sheets(1)
            For i = 2 To lastrow
                If .Cells(i, 8).Value <> .Cells(i - 1, 8).Value Then
                    StartRow = .Cells(i, 7).Row
                End If
                If .Cells(i, 8).Value <> .Cells(i + 1, 8).Value Then
                    EndRow = .Cells(i, 8).Row
                    .Range(Cells(StartRow, 1), Cells(EndRow, lastColumn)).Select
                Else
                    GoTo 1
                End If
                recepient = .Cells(i, 8).Value
                Manager = .Cells(i, 8).Value
                ID = .Cells(i, 7).Value
                Set Source = Selection.SpecialCells(xlCellTypeVisible)
                On Error GoTo 0
            
                If Source Is Nothing Then
                    MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
                    Exit Sub
                End If
            
                With Application
                    .ScreenUpdating = False
                    .EnableEvents = False
                End With
                
                Set wb = ActiveWorkbook
                Set Dest = Workbooks.Add(xlWBATWorksheet)
            
                header.Copy
                With Dest.Sheets(1)
                    .Cells(1, 1).PasteSpecial Paste:=8
                    .Cells(1, 1).PasteSpecial Paste:=xlPasteValues
                    .Cells(1, 1).PasteSpecial Paste:=xlPasteFormats
                    .Cells(1, 1).Select
                    Application.CutCopyMode = False
                End With
                Source.Copy
                With Dest.Sheets(1)
                    .Cells(2, 1).PasteSpecial Paste:=8
                    .Cells(2, 1).PasteSpecial Paste:=xlPasteValues
                    .Cells(2, 1).PasteSpecial Paste:=xlPasteFormats
                    .Cells(2, 1).Select
                    Application.CutCopyMode = False
                    ActiveWorkbook.SaveAs "\\ant\dept-eu\PRG10\HR\prg10-eu-hr-services\T2-EMEA-Corp\Slovakia\6. Payroll\Discrepancy Notifications\Generated Excels\" & ID & "_" & Manager & "_Pending codes"
                End With
    Last edited by orhanceliloglu; 04-26-2018 at 08:48 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sub-Forum for Power Query & Power BI?
    By AliGW in forum Suggestions for Improvement
    Replies: 7
    Last Post: 08-26-2018, 05:25 PM
  2. Replies: 0
    Last Post: 04-05-2018, 01:16 AM
  3. error in power query & power pivot
    By Baldev Kumar in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 01-03-2018, 01:34 AM
  4. [SOLVED] Multiple tasks on tables in Power Query
    By wrybel in forum Excel General
    Replies: 11
    Last Post: 08-01-2017, 03:17 AM
  5. Get & Transform (Power Query) not showing certain tables
    By BamBamMoneyBags in forum Excel General
    Replies: 0
    Last Post: 03-22-2017, 12:22 PM
  6. Denesting tables in XML data imported into Power Query
    By Cuine100 in forum Excel General
    Replies: 1
    Last Post: 08-11-2016, 09:30 PM
  7. Power Query - how to append tables
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2015, 04:55 AM

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