ReBuild a concatenated cell based on format of second cell - VBA solution needed

jfarc

Active Member
Joined
Mar 30, 2007
Messages
316
I'm pulling Sale & Cost data from a mainframe into Excel, which has multi-value data stored in a single variable(cell), one field for multiple Costs & one field for multiple Sales from a single Invoice.

The problem is the Sale field from the mainframe fills in '0.00' when there is no pricing info for a particular line on the Invoice, but the Cost field doesn't do this, it only reports Cost amounts that are greater than zero. I want to rebuild the Cost field so it has the missing '0.00' for each corresponding Sale of '0.00'.

The example fields below will make this more clear on what is happening and what is needed. The example has 3 rows of data. Each row can have a variable number of separate dollar fields each separated by a space.

This data is in Column-K Sale info. Each line below is a single cell(row) that contains multiple Sale $figures:
Code:
154.63 0.00 0.00 0.00 0.00 140.00 0.00 0.00
0.00 0.00 25.33 0.00 0.00 20.16 15.32
0.00 4.24 0.00 2.48 146.68

The data is in Column J Cost info. This is first 3 rows where only the Cost info that is greater than zero is displayed:
Code:
101.41 96.00
19.48 12.50 9.50
3.03 1.77 95.35

So in the first row from Col-J 101.41 corresponds to the Col-K 154.63 and Col-J 96.00, the 2nd $figure corresponds to Col-K 140.00, which is the 6th $figure. This row has a total of 8 Sale figures, but only 2 Cost figures.

In the second row from Col-J 19.48, the 1st $figure corresponds to the Col-K 25.33, which is the 3rd $figure and so on.... This row has a total of 7 Sale figures.

In the end, what I need is to rebuild each cell in Col-J so that the missing '0.00' amounts are filled in as follows so that each and every dollar amount in Col-J fully corresponds one-for-one to each dollar amount in Col-K and remain in the same original format separated by spaces:
Code:
101.41 0.00 0.00 0.00 0.00 96.00 0.00 0.00
0.00 0.00 19.48 0.00 0.00 12.50 9.50
0.00 3.03 0.00 1.77 95.35

Once I rebuild Col-J, I already have working code to process the file from that point.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Ok, I came up with the following inside my entire file processing loop to resolve this issue and it's working nicely:
Code:
        jNew = ""
        jCount = 0
        j1Split = Split(Range("J" & x), " ")
        k1Split = Split(Range("K" & x), " ")
        For iCount = LBound(k1Split) To UBound(k1Split)
            If k1Split(iCount) <> 0 Then
                jNew = jNew & j1Split(jCount) & " "
                jCount = jCount + 1
            Else
                jNew = jNew & "0.00" & " "
            End If
        Next iCount
        Range("J" & x) = Left(jNew, Len(jNew) - 1)
 
Upvote 0

Forum statistics

Threads
1,224,416
Messages
6,178,509
Members
452,853
Latest member
philipnjk64

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