VBA How To Paste With Blank One Column Over

0 votes

How can I change my code such that a blank column appears between pastes? This was pasted onto a different sheet after looping each filter. The code below is functional, however, it should start in column B, not C.

Set shtcopy = Sheets("Summary Copying")
Set shtpaste = Sheets("Summary")
        
        shtcopy.PivotTables
            pt.TableRange1.Copy
            shtpaste.Cells(10, Columns.Count).End(xlToLeft).Offset(, 2).PasteSpecial Paste:=xlPasteValues
            shtpaste.Cells(10, Columns.Count).End(xlToLeft).Offset(, -4).PasteSpecial Paste:=xlPasteFormats
        shtpaste.Cells.Columns.AutoFit
Jan 26, 2023 in Others by Kithuzzz
• 38,010 points
366 views

1 answer to this question.

0 votes

Try this:

Option Explicit

Sub CopyPaste()

    Dim pt As PivotTable, wb As Workbook, n As Long
    Dim shtCopy As Worksheet, shtpaste As Worksheet
    
    Set wb = ThisWorkbook
    With wb
        Set shtCopy = .Sheets("Summary Copying")
        Set shtpaste = .Sheets("Summary")
    End With
         
    Set pt = shtCopy.PivotTables(1)
    pt.TableRange1.Copy
         
    With shtpaste
        n = .Cells(10, .Columns.Count).End(xlToLeft).Column
        If n < 2 Then
            n = 2
        Else
            n = n + 2
        End If
    
        .Cells(10, n).PasteSpecial Paste:=xlPasteValues
        .Cells(10, n).PasteSpecial Paste:=xlPasteFormats
        .Cells.Columns.AutoFit
    End With
  
End Sub
answered Jan 26, 2023 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer
0 votes
0 answers

How to drop all tables from a database with one SQL query?

What if we don't want to type ...READ MORE

May 28, 2022 in Others by Sohail
• 3,040 points
185 views
0 votes
0 answers

How to drop all tables from a database with one SQL query?

drop all tables without typing name. Is ...READ MORE

Jun 7, 2022 in Others by polo
• 1,480 points
180 views
0 votes
1 answer

How to insert a picture into Excel at a specified cell position with VBA

Try this: With xlApp.ActiveSheet.Pictures.Insert(PicPath) With ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,420 points
1,985 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
902 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,222 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
514 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,670 points
756 views
0 votes
1 answer

How to print an Excel Sheet using VBA with Nitro PDF Creator in Excel 2016

you can use the built-in excel facilities ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,420 points
863 views
0 votes
1 answer

Transpose column on one sheet to row on another, with linking

select A1:J1 in worksheet B and enter: =TRANSPOSE('worksheet ...READ MORE

answered Sep 25, 2022 in Others by narikkadan
• 63,420 points
992 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP