VBA Code: Copy Column down to match with text in the next column

hanz753

Board Regular
Joined
Aug 9, 2017
Messages
53
Hello, I am not sure if I can use a formula or a VBA code to do this task.


COS
COSPurchase
COS Inventorys
COS
Inventory
Inventory
Stock
Adjustments
TOTAL COS
<colgroup><col width="64" style="width: 48pt;"> <col width="325" style="width: 244pt; mso-width-source: userset; mso-width-alt: 11885;"> <col width="287" style="width: 215pt; mso-width-source: userset; mso-width-alt: 10496;"> <tbody> </tbody>
I Need the first colum to continue down as "COS" and stop at "TOTAL COS".

Thank you
Hanz
 
If I were to use different description in column B ( Not Inventor and Bonus)

COSINVENTORY Warehouse
COSINVENTORY Store
COSINVENTORY Shops
COSINVENTORY Warehouse2
COSINVENTORY
COSINVENTORY
COSTOTAL COS
SALEBONUS 1
BONUS 2
BONUS 3
BONUS 4
TOTAL SALES




<colgroup><col width="95" style="width: 71pt; mso-width-source: userset; mso-width-alt: 3474;"><colgroup><col width="182" style="width: 137pt; mso-width-source: userset; mso-width-alt: 6656;"><tbody>
</tbody>
Is there a VBA code that would fill from A1 to "TOTAL COS" with COS. And anything above Total sales fills with SALES.
Also I would just like to add, this not the full set data. There is more data and criterias.

I thought if know the code to apply for the set I would be able to apply to the rest.

Hanz

<colgroup><col width="64" style="width: 48pt;" span="2"><tbody>
</tbody>
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Will the 1st line of each "section" always have a value, like


Excel 2013/2016
AB
1COSINVENTORY Warehouse
2INVENTORY Store
3INVENTORY Shops
4INVENTORY Warehouse2
5INVENTORY
6INVENTORY
7TOTAL COS
8SALEBONUS 1
9BONUS 2
10BONUS 3
11BONUS 4
12TOTAL SALES
13ScrapWaste
14Waste
15Waste
16Waste
17Waste
18Total Watse
19AnythingSomething
20Something
21Something
22Total something
Sheet1
 
Upvote 0
Sorry for the confusion,

In Column A, I need the rows from A2 to "TOTAL REVENUE" ( TOTAL REVENUE is in column "C") to be filled with "REVENUE".

Below that, I would need the Cells to be filled with "COS" until "Cost of Sales" ( Cost of Sales is in column C)

This would contiue for Gross Profit, Finance Cost, Service, Admin and Income.

Thank you for your help

Hanz
 
Upvote 0
How about
Code:
Sub FillColA()
   Dim Rng As Range
   Dim Ar As Areas
   With Range("B1", Range("B" & Rows.Count).End(xlUp))
      .Replace "total", "=xxxTotal", xlPart, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Areas
      .Replace "=xxxTotal", "Total", xlPart, , False, , False, False
   End With
   For Each Rng In Ar
      With Rng.Offset(Rng.Count).Resize(1, 1)
      Rng.Offset(, -1).Value = Mid(.Value, InStr(1, .Value, " ") + 1)
      End With
   Next Rng
End Sub
 
Upvote 0
It doesn't seem to be working. Having a long hard think about this I would need to enter the text in manually.

Sorry for the confusion, I really appreciate your help.

In Column A, I need the rows from A2 to "TOTAL REVENUE" ( TOTAL REVENUE is in column "C") to be filled with "REVENUE".

Below that, I would need the Cells to be filled with "COS" until "Cost of Sales" ( Cost of Sales is in column C)

This would contiue for Gross Profit, Finance Cost, Service, Admin and Income.

Thank you for your help

Hanz
 
Upvote 0
Try
Code:
Sub FillColA()
   Dim Rng As Range
   Dim Ar As Areas
   With Range("C2", Range("C" & Rows.Count).End(xlUp))
      .Replace "total", "=xxxTotal", xlPart, , False, , False, False
      Set Ar = .SpecialCells(xlConstants).Areas
      .Replace "=xxxTotal", "Total", xlPart, , False, , False, False
   End With
   For Each Rng In Ar
      With Rng.Offset(Rng.Count).Resize(1, 1)
      Rng.Offset(, -2).Resize(Rng.Count + 1).Value = Mid(.Value, InStr(1, .Value, " ") + 1)
      End With
   Next Rng
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,086
Messages
6,128,736
Members
449,466
Latest member
Peter Juhnke

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