Consolidate two columns in one sheet with VBA- HELP PLEASE

fireby40

New Member
Joined
Jun 19, 2018
Messages
2
HI everyone!

I am trying to consolidate data from two columns next to each other for a macro. When I recorded the macro, it gave me this code in VBA:

Selection.Consolidate Sources:= _
"'C:\Users\random\Desktop\[DensityTest.csv]DensityTest'!R2C2:R823C3", _
Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False

However when I try to run this macro on a different spreadsheet, it will consolidate the data from this original worksheet and not the new one. Is there VBA code I can use to replace these lines so that I can consolidate the columns in a new worksheet?

Thanks so much!
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Roderick_E

Well-known Member
Joined
Oct 13, 2007
Messages
2,051
You need to change the red parts to point to the new sheet and the range you want

Selection.Consolidate Sources:= _

"'C:\Users\random\Desktop\[DensityTest.csv]DensityTest'!R2C2:R823C3", _
Function:=xlSum, TopRow:=True, LeftColumn:=True, CreateLinks:=False
 

Watch MrExcel Video

Forum statistics

Threads
1,095,247
Messages
5,443,326
Members
405,227
Latest member
Ankit Jain

This Week's Hot Topics

Top