Move data from a column to another

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
888
Hi to all of you, kindly require to provide me support so that to prepare a VBA code which should run through the range “(I29:I14800)” and if cells contain prices should cut any texts or numbers from column “C” and placed them in column “A” opposite description’s cells.
In additions, prices should place them opposite description’s row too in row "I". I present below my original data and the expected result. Therefore that, this post is similar to my previous but with new options. Apologies for any inconvenience I caused. Thank you all in advance!
 

Attachments

  • 1726481581637.png
    1726481581637.png
    56.2 KB · Views: 16
  • clipboard-1726471208528.png
    clipboard-1726471208528.png
    56.2 KB · Views: 14
  • clipboard-1726471225949.png
    clipboard-1726471225949.png
    57 KB · Views: 17

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Ever think of using power query to handle it
Book1
AB
1DescriptionPrice
289000101
3Lemonade tin 330rnI1.2
489000205
5Orange Squash 750ml2.35
689000313
7Lemon Squash 750m'2.35
892030314
9Wholemeal sliced 1000gr3.25
10WHY00750
11Whisky 750ml15.25
12WHY00500
13 Whisky 500ml9.75
14BAGSSM
15Smal bags2.35
Sheet1


Book1
ABC
1CodeDescriptionPrice
289000101Lemonade tin 330rnI1.2
389000205Orange Squash 750ml2.35
489000313Lemon Squash 750m'2.35
592030314Wholemeal sliced 1000gr3.25
6WHY00750 Whisky 750ml15.25
7WHY00500 Whisky 500ml9.75
8BAGSSMSmal bags2.35
Table1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type any}, {"Price", type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Inserted Modulo" = Table.AddColumn(#"Added Index", "Modulo", each Number.Mod([Index], 2), type number),
    #"Added Custom" = Table.AddColumn(#"Inserted Modulo", "Code", each if [Modulo] = 0 then [Description] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Description1", each if[Modulo]=1 then [Description] else null),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom1",{"Description", "Index", "Modulo", "Code", "Description1", "Price"}),
    #"Filled Down" = Table.FillDown(#"Reordered Columns",{"Code"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Modulo] = 1)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Description", "Index", "Modulo"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Description1", "Description"}})
in
    #"Renamed Columns"
 
Upvote 0
Thank you Kerryx for your support and your time spent for my project. Is so complicate for to convert the spreadsheet to table and use "Power Query" and so I prefer a VBA code. I appreciated you attempt to solve my issue but unfortunately for me I couldn't with your code. Thank you once again. Have a great day!
 
Upvote 0
Actually PQ is very simple easier than VBA , if you want to know more here are some great links from alansidman

 
Upvote 0
Typically you want the output consolidated and in a cleaner format.
Does you data heading really start at row 27 ?
Do you really want it back in the same place with blank columns and blank rows in between ?
 
Upvote 0
Just to keep it moving along, give this a try:

VBA Code:
Sub ReformatData()

    Dim sht As Worksheet
    Dim rng As Range
    Dim lastRow As Long
    Dim arr As Variant
    Dim i As Long, colPrice As Long
    
    Set sht = ActiveSheet
    With sht
        lastRow = .Range("C" & Rows.Count).End(xlUp).Row + 1
        colPrice = 9
        Set rng = .Range(.Cells(28, "A"), .Cells(lastRow, "I"))
        arr = rng.Value
    End With

    For i = 1 To UBound(arr)
        If arr(i, colPrice) <> "" Then
            arr(i, 1) = arr(i, 3)
            arr(i, 3) = arr(i + 1, 3)
            arr(i + 1, 3) = Empty
        End If
    Next i
    
    rng.Value = arr
    
End Sub
 
Upvote 0
Solution
Thank you Alex! Nice code which works perfect and according to my project. Regarding your above notes kindly be informed that the rows from 'A1" : "I27 are just headings e.g.
- supplier's Brand Name,
- Invoice date
- Credit period
- Account number
- e.t.c.
In addition, the blank columns have data too, like quantity, unit measure, expire date e.t.c. Therefore that, the above is an extract of the data and i entered only the columns and rows which they should be affected. I express my apologies if not mentioned the contents of all columns and rows, this was causes the code complicate.
However, i express my thanks once again. Have a lovely day!
 
Upvote 0

Forum statistics

Threads
1,221,531
Messages
6,160,357
Members
451,642
Latest member
mirofa

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