Insert 2 columns from 1 sheet to another using VBA

Sukanya

New Member
Joined
Dec 12, 2017
Messages
3
This is the code i have worked with. It is showing the error 1004 that the copy area and paste area are not in the same size. Please help me with the issue?



Sheets("ESTemplate").Activate
Sheets("ESTemplate").Columns("A:B").Select
Selection.Copy
Sheets("Effort_Summary").Activate
For j = 2 To (4 + ((Sheets.Count - SheetCount) * 2))
MsgBox Sheets.Count

If Cells(3, j).Value = "Total" Then
ActiveSheet.Columns(j).Select
Selection.Insert Shift:=xlRight
Selection.Paste

ActiveSheet.Cells(3, j) = WKSheetName
Exit For

End If
Next j
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You need to tell us in words what your wanting to do:

I see you want to Copy Columns A & B

But what you want to do after that is not clear to me
 
Upvote 0
I need to copy 2 columns from 1 excel sheet to another. Second Excel sheet containing a table.If the column value returns "Total" , then i need to insert 2 more columns.Always "Total" filed is the last entry of the table. I need to paste 1st excel sheet's copied data here..For Condition indicates the column size of the table
 
Upvote 0
Solved the problem with a small change in the code.. Anyways thanks for your great time


For j = 2 To (4 + ((Sheets.Count - SheetCount) * 2))
If ActiveSheet.Cells(3, j).Value = "Total" Then
ActiveSheet.Columns(j).Insert Shift:=xlRight
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top