Cut-Insert running on wrong sheet

EngSantiago

New Member
Joined
Mar 19, 2014
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi all,

It's been a few years since I don't create a macro from scratch and I'm scratching with a simple issue here. I'm basically duplicating the "Default" sheet and naming it as "BOM Analysis". I'm setting the new sheet as active but the cut-insert code making the changes on the "Default" sheet not on the "BOM Analysis" sheet. How do I fix this?

VBA Code:
Sub CleanUpBOM()
Sheets("Default").Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = "BOM Analysis"
Sheets("BOM Analysis").Columns("A:G").AutoFit
Sheets("BOM Analysis").Activate
ActiveSheet.Cells(2, 2).Select
Columns("D:D").Cut
Columns("H:H").Insert Shift:=xlToRight
'more to come :)

End Sub
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

aRandomHelper

Board Regular
Joined
Jan 14, 2021
Messages
225
Office Version
  1. 2016
Platform
  1. Windows
The easiest way is probably to reference the worksheet accordingly.
VBA Code:
Sub CleanUpBOM()
Dim ws1 As Worksheet, ws2 As Worksheet
Set ws1 = Sheets("Default")
ws1.Copy Before:=Sheets(Sheets.Count)
ActiveSheet.Name = "BOM Analysis"
Set ws2 = Sheets("BOM Analysis")
ws2.Columns("A:G").AutoFit
ws2.Cells(2, 2).Select
ws2.Columns("D:D").Cut
ws2.Columns("H:H").Insert Shift:=xlToRight
'more to come :)

End Sub

Edit: not sure where you want to cut from/insert to, but you get the idea, edit accordingly.
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,529
Messages
5,625,347
Members
416,096
Latest member
forevans

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
Top