Subtract previous cells in a row and report in new sheet

ekalavya

New Member
Joined
Mar 5, 2014
Messages
31
I have a data file that looks like this:

Col1Col2Col3Col4Col5Col6Col7Col8Col9Col10Col11Col12Col13Col14
10B168850000A176250000B189350000A220150000B272571316
20A226950000B272571316
30A28250000B38650000A242950000B261450000A265550000B272571316
40A39650000B228150000A272571316
50A39650000B239650000A272571316
60A19250000B45750000A242950000B249950000A272571316

<tbody>
</tbody>

For each sample (Col1), I want to subtract the values spanning each letter. For example, resulting values for sample 1 would be: Col4-Col2 for B, Col6-Col4 for A, Col8-Col6 for B, Col10-Col8 for A, and so on until the last column. The number of columns varies by the sample, with minimum of 4 columns to maximum of about 100. There are about 2500 rows.

At the end, I would prefer to have the result in a new sheet as follows:

1B168850000
1A7400000
1B13100000
1A30800000
1B52421316
2A226950000
2B45621316
3A28250000
3B10400000
and so on

<tbody>
</tbody>

Any help would be greatly appreciated. Thank you.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi.
Would you try a solution via macro?

Code:
Sub Test()
 Dim LR As Long, LC As Long, k As Long, x As Long, m As Long
 Dim wsO As Worksheet, wsD As Worksheet
  Set wsO = Sheets("Sheet1"): Set wsD = Sheets("Sheet2")
  wsD.[A:B] = ""
  LR = wsO.Cells(Rows.Count, 1).End(3).Row
   For k = 2 To LR
    LC = wsO.Cells(k, Columns.Count).End(1).Column
     For x = 3 To LC - 1 Step 2
      With wsD
       .Cells(m + 2,  1) = wsO.Cells(k, 1) & wsO.Cells(k, x)
       .Cells(m + 2, 2) = wsO.Cells(k, x + 1) - wsO.Cells(k, x - 1)
       m = m + 1
      End With
     Next x
    Next k
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,559
Messages
6,120,208
Members
448,951
Latest member
jennlynn

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