How to copy a formula to every other column

Pandrade

New Member
Joined
Apr 13, 2020
Messages
36
Office Version
  1. 365
Platform
  1. Windows
Hi,
How can I copy a formula with more than a thousand columns to every other column in Excel?
 
Now I don't know if we are talking of a new problem or the initial one, with different details...

Let me go with this different proposal:
1) Insert this macro in a Standard Module of your vba project:
VBA Code:
Sub PanCopy()
Dim LastC As Long, LastR As Long
Dim tStartR As Long, tStartC As Long
'
'
LastC = Cells.Find(What:="*", After:=[A1], _
              SearchOrder:=xlByColumns, _
              SearchDirection:=xlPrevious).Column
On Error GoTo 0
'
tStartC = Selection.Cells(1, 1).Column
tStartR = Selection.Cells(1, 1).row
Selection.Offset(, 1).Resize(, LastC).ClearContents

Selection.Copy
For I = tStartC + 2 To LastC Step 2
    Cells(tStartR, I).PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
Next I
Application.CutCopyMode = False
End Sub
2) you write the formulas that do the job on the first column of data; from what I see in the nanopicture, you need formulas in L48-L49-L50. Please don't use "absolute addressing" (fo example: $L$2:$L$46) but only "relative addressing" (like L2:L46).
3) when you are ok, select ALL the formula that you wish to replicate to the right
4) select ALL the formula you wish to repeat to the right then run this new Sub PanCopy

Your formula will be copied to the right till the last column, starting from column "selection+2" and stepping by 2

Bye
 
Upvote 0

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.
Anthony47 I really appreciate your assistance. The first code worked for count, but in addition I need to sum, and then get the average. Again thank you for taking the time.
 
Upvote 0
Was the approach described in post #21 useful? I mean: you set the formulas in the first column and the macro copy them
 
Upvote 0
Anthony47,

Approach described in post #21 almost works as needed except it doesn't account for columns of different lengths. How can that be addressed. I get the sums where they are supposed to be but on columns that are longer I get the little green arrow in the upper left corner of the cell because it doesn't sum all the quantities for those longer columns.
 
Upvote 0
That's because I'm using the sum function on the first salary column, so it only sums the range of the first column. The second formula I will use your VBA to copy will be average. That one should work fine but for the sum it needs something else.
 
Upvote 0
It only sums the range of the first column when sum function is copied to the rest of the salary columns.
 
Upvote 0
It only sums the range of the first column when sum function is copied to the rest of the salary columns.
If the formula, when copied, return always the sum of the initial column then it means you used "absolute addresses" in its argument; for example =SUM($L$2:$L$47)
You must use "relative addresses", for example L2:L47

If you don't follow me then tel us which formulas you set and in which position and we'll try to modify them

Bye
 
Upvote 0
Anthony47,

Thank you again. The way I compensated was I increased the range for the first column when entering the original formula, since the rest of the cells are empty it doesn't affect the result for the columns with smaller ranges but it does make it so that the columns with longer ranges will include all cells. I will try it again, this time by clicking the relative addresses button and see if that works.
 
Upvote 0
What is "the relative address button"?
I talked about your formulas...
 
Upvote 0

Forum statistics

Threads
1,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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