Conquering VBA Copy Sheet & autofit Columns after paste

emack1230

New Member
Joined
Jul 9, 2022
Messages
34
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good evening all,
I have my vba code triggering off 2 different validation lists on our main tab, based on validation selection the vba will copy a job qualification tab from a different workbook and paste it into our new hire workbook as a new tab. Everything works but I can't seem to get the autofit column string to work. Here is the copy paste vba code. Is this where I put the columnwidth? Thanks in advance.

Sub OpenWorkbook()

Dim wb As Workbook, bk As Workbook

Set bk = Workbooks("Hybrid packet.xlsm") 'assumed open


Set wb = Workbooks.Open("originating workbook") 'you would need the full address and name of workbook


wb.Worksheets("BAGGER OPERATOR").Range("A1:I500").Copy bk.Worksheets("Job Qualification 1").Range("A1")


wb.Close SaveChanges:=True

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Before the end of the above sub (and assuming it's the "Job Qualification 1" sheet you want it applied to) try this:

VBA Code:
bk.Worksheets("Job Qualification 1").UsedRange.EntireColumn.AutoFit
 
Upvote 0
Solution

Forum statistics

Threads
1,214,384
Messages
6,119,201
Members
448,874
Latest member
Lancelots

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