Create a new column in an existing sheet based on certain conditions

amrita17170909

Board Regular
Joined
Dec 11, 2019
Messages
74
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hi All,

I am trying to add a column by the name of bill split to an existing sheet by name of "Copied Data".

The code should be able to do following things:
1. Create a Column by name of "Bill Split" ( Location - next to a column by name of GL_Account)
2. Check what's the first number of the GL Account and on that basis columkn "Bill Split" will be populated
e.g If it starts with 1 and 2 then it should be "Capex"
If it starts with 3 and 4 it should be "Error"
If it starts with 5 it should be "Capex"

I have started writing the code but unable to understand how should my loop look like :

VBA Code:
Sub create_bill_split()

Dim LastRow As Long

 With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
    End With
 
Worksheets("Copied Data").Activate
    
 With Worksheets("Copied Data")
 
   LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
          
  .Columns("AI").EntireColumn.Insert _
            Shift:=xlShiftToRight
            
  .Range("AI" & lSumRow + 1 & ":AI" & LastRow).Formula = "???/"
     For ctr = LastRow To 5 Step -1
            
      
    Next ctr

 End With
 
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Since I cannot see the worksheet, I am guessing based on the narrative in the OP. But give this a try for your loop.

Code:
For ctr = LastRow To 5 Step -1
    Select Case Left(.Cells(ctr, "AJ").Value, 1)
        Case 1, 2, 5
            .Cells(ctr, "AI") = "Capex"
        Case 3, 4
            Cells(ctr, "AI") = "Error"
        Case Else
            MsgBox "Criteria Less Than 1 Or Greater Than 5"
        End Select
Next ctr
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,721
Members
449,093
Latest member
Mnur

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