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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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.
 
Upvote 0
Solution

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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