Transfer Data based off a criteria to certain Column

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
893
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I need some help to transfer my data to specific columns on my destination sheet. The ability to modify it if it changes I have a line of code that transfers based off a criteria but now to specific columns adds a bit of complexity for me. See for example the below.


Source data - the amount of rows may change but always starts on row 11:
Book2
ABCDEFGHIJKLMNOPQ
1
2
3
4
5
6
7
8
9
10
11ConcatenateDateAccountIndicatorGroupCurrencyPriceUnit HoldersValueFactorAverageTotal AssetsTotal LiabilitiesRate 1Rate 1 %Rate 2Rate 2 %
12AAAF1/10/2025AAAF1USD$101000$1000.0001$10100$500.00510%0.09590%
Source


Destination - With a header starts on row 2. Should look like this:
Book2
ABCDEFGHIJKLMNOPQR
1DateMain AccountUnique IDIndicatorMain Account GroupCurrencyPriceUnit HoldersValueFactorPre PriceAverageTotal AssetsTotal LiabilitiesRate 1Rate 1 %Rate 2Rate 2 %
2AAAF1USD1010001000.000110100500.0050.10.0950.9
3
Destination


The data must transfer based off the criteria in column D = F. As there will also be other indicators of AZ on it that I do not want to bring over. Thanks in advance - any help is always appreciated. This is a mockup by actual data is over 300 rows if it matters.
 
Different method without loop.
Code:
Sub test()
    Dim x, cols
    cols = "2,3,#,4,5,6,7,8,9,10,#,"
    With Sheets("source")
        With .Rows("11:" & .Cells.SpecialCells(11).Row + 1).Resize(, _
                .Cells(11, Columns.Count).End(xlToLeft)(1, 2).Column)
            cols = Replace(cols, "#", .Columns.Count) & Join( _
                Application.Sequence(1, .Columns.Count - 10, 11, 1), ",")
            x = Application.Index(.Value, Evaluate("row(2:" & .Rows.Count & ")"), Split(cols, ","))
        End With
    End With
    With Sheets("destination").[a1].CurrentRegion
        .Offset(1).ClearContents
        .Rows(2).Resize(UBound(x)) = x
    End With
End Sub
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Different method without loop.
Code:
Sub test()
    Dim x, cols
    cols = "2,3,#,4,5,6,7,8,9,10,#,"
    With Sheets("source")
        With .Rows("11:" & .Cells.SpecialCells(11).Row + 1).Resize(, _
                .Cells(11, Columns.Count).End(xlToLeft)(1, 2).Column)
            cols = Replace(cols, "#", .Columns.Count) & Join( _
                Application.Sequence(1, .Columns.Count - 10, 11, 1), ",")
            x = Application.Index(.Value, Evaluate("row(2:" & .Rows.Count & ")"), Split(cols, ","))
        End With
    End With
    With Sheets("destination").[a1].CurrentRegion
        .Offset(1).ClearContents
        .Rows(2).Resize(UBound(x)) = x
    End With
End Sub
Seems cleaner but doesn't seem to be working is it missing the indicator must equal F or Blank (I added that modification myself later on Dantes code)?
 
Upvote 0

Forum statistics

Threads
1,225,738
Messages
6,186,736
Members
453,369
Latest member
juliewar

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