insert column and calculate between two columns

Hasson

Active Member
Joined
Apr 8, 2021
Messages
401
Office Version
  1. 2016
Platform
  1. Windows
hi
I have values in two columns sales and returns I would insert a new column name the header is QTY then should subtract COL E from COL F
SHEET input
1.xlsx
ABCDEF
1datecommidatymanfmadesalesreturns
212/5/2021ff-1200it-1000it10005
312/6/2021ff-1201it-1001ja200-
412/7/2021ff-1202it-1002br25845
512/8/2021ff-1203it-1003ur205
612/9/2021ff-1204it-1004tr30012
712/10/2021ff-1205it-1005it10-
812/11/2021ff-1206it-1006ja50-
912/12/2021ff-1207it-1007br12-
1012/13/2021ff-1208it-1008ur45
1112/14/2021ff-1209it-1009tr12010
1212/15/2021ff-1210it-1010it1012
input

expected result
1.xlsx
ABCDEFG
1datecommidatymanfmadesalesreturnsQTY
212/5/2021ff-1200it-1000it10005955
312/6/2021ff-1201it-1001ja200-200
412/7/2021ff-1202it-1002br25845213
512/8/2021ff-1203it-1003ur20515
612/9/2021ff-1204it-1004tr30012288
712/10/2021ff-1205it-1005it10-10
812/11/2021ff-1206it-1006ja50-50
912/12/2021ff-1207it-1007br12-12
1012/13/2021ff-1208it-1008ur4545
1112/14/2021ff-1209it-1009tr12010110
1212/15/2021ff-1210it-1010it1012-2
input
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Try

VBA Code:
Sub NewCol()
  With Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row)
    .Cells(0).Value = "QTY"
    .Formula = "=E2-N(F2)"
  End With
End Sub
 
Upvote 0
wow ! it's quick , but I would the same formatting and borders like columns which precede them and no show the formula in the column
 
Last edited:
Upvote 0
the same formatting and borders like columns which precede them and no show the formula
Then try

VBA Code:
Sub NewCol()
  With Range("G1:G" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=E1-N(F1)"
    .Value = .Value
    .Cells(1).Value = "QTY"
    .Offset(, -1).Copy
    .PasteSpecial xlPasteFormats
  End With
End Sub
 
Upvote 0
thanks, but can you delete the selection for column which precede it after run the macro ,please

and what means letter N in your code ?
 
Upvote 0
Try this version.
The N() is to stop an error value on the rows that have a "-" in the returns column by turning that "-" into a 0.
N function

VBA Code:
Sub NewCol()
  Application.ScreenUpdating = False
  With Range("G1:G" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=E1-N(F1)"
    .Value = .Value
    .Cells(1).Value = "QTY"
    .Offset(, -1).Copy
    .PasteSpecial xlPasteFormats
  End With
  Application.CutCopyMode = False
  Range("G1").Select
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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