Help with Vba code.

jaymack

New Member
Joined
Nov 29, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Need help in turning a manual process into a automated method using a vba
code

I need a code to firstly delete column B and C, then add a column into Column B, then one right of C,D,E,F and G

Then to copy Cell C9 into all available cells in Column B and D9 into
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try this on a copy of your Workbook.
VBA Code:
Option Explicit

Sub ArrangeSheet()
Dim i As Long
With Range("B:C")
    .Delete
End With
For i = 8 To 2 Step -1
    Columns(i).Insert
Next i
End Sub
 
Upvote 0
@Skyybot I think you'll need to change 8 to 7 (do the task the OP did in post 1 up to and including the inserting a column after selecting column B, highlight a cell in column G and add some data in columns H and I, then insert another column into column B so you have 2 blank columns for the initial delete, then run the code and check where the last column has been inserted compared to the highlighted cell)

Obviously you can't code for the last part of the question as the question is incomplete
 
Upvote 0
@MARK858 , I tried 7 first but the result did not match what I think OP is looking for even though the request is incomplete. After the delete of B:C I assumed that there could be data in column H and beyond.
 
Upvote 0
They have inserted a column already into B so column G would be as below
Book1
ABCDEFGHI
1Order IDSP NameCategory NameShip ViaQuantityOrder Totalbbnmmmm
2108-5-N72Steven BuchananMeat/PoultryAir10459.7848
3105-13-F35Margaret PeacockSeafoodAir10206.6136
4106-1-N88Margaret PeacockBeveragesRoad14564.4026
5109-12-N44Michael SuyamaDairy ProductsRoad5150.1038
6110-23-N46Laura CallahanBeveragesSea18432.5616
Sheet5


So you would be starting with

Book1
ABCDEFGHIJ
1Order IDInitial deleteInitial deleteSP NameCategory NameShip ViaQuantityOrder Totalbbnmmmm
2108-5-N72Initial deleteInitial deleteSteven BuchananMeat/PoultryAir10459.7848
3105-13-F35Initial deleteInitial deleteMargaret PeacockSeafoodAir10206.6136
4106-1-N88Initial deleteInitial deleteMargaret PeacockBeveragesRoad14564.4026
5109-12-N44Initial deleteInitial deleteMichael SuyamaDairy ProductsRoad5150.1038
6110-23-N46Initial deleteInitial deleteLaura CallahanBeveragesSea18432.5616
Sheet5
 
Upvote 0
Let's assume the following original layout
Book1
BCDEFGHIJKLMN
1Col1Col2Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13
Sheet1

In my mind this is what OP is looking for.
Book1
ABCDEFGHIJKLMNO
1Col1Col4Col5Col6Col7Col8Col9Col10
Sheet1
 
Upvote 0
Following the OP's instructions
Your start data
Book1
ABCDEFGHIJKLMN
1Col0Col1Col2Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13
Sheet5


firstly delete column B and C
Book1
ABCDEFGHIJKL
1Col0Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13
Sheet5

then add a column into Column B
Book1
ABCDEFGHIJKLM
1Col0Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13
Sheet5

then one right of C,D,E,F and G
Book1
ABCDEFGHIJKLMNOPQR
1Col0Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13
Sheet5
 
Upvote 0
I see it now. So my original thought was correct and over-thinked it. That was one of the reasons I was a bad test taker.
 
Upvote 0
I see it now. So my original thought was correct and over-thinked it. That was one of the reasons I was a bad test taker.
I wouldn't say that yet as the OP hasn't responded, with the question being incomplete and no sample data either of us might be right or both totally wrong :LOL:
 
Upvote 0

Forum statistics

Threads
1,225,739
Messages
6,186,746
Members
453,370
Latest member
juliewar

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