Pull Data from One Sheet's Range to Another Sheet based on Criteria

NewFrugal

New Member
Joined
Jun 22, 2022
Messages
22
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
  2. Mobile
Hello. Please bare with me as this is my first post although I've visited as a guest sporadically over the years. I've tried researching how to automatically populate data from one sheet into another based on specific criteria, and I haven't been lucky in finding a suitable answer. Perhaps I'm not searching under the correct terms.

Specifically, I need to know how to automatically copy negative numbers from the original source sheet into a second sheet, and positive numbers into a third sheet. For clarity, I download daily bank transactions with many lines, and I figured there has to be a simpler way to do this rather than copying and pasting a lot of data. I need help having one sheet pull the posting date, reference, amount and class into a Debits sheet (negative numbers) and Credits sheet (positive). I'm assuming an advanced filter should be used, but I don't have unique data for this to easily occur. Shouldn't a sheet be able to look up a range of another, read it, and copy the specific criteria I'm seeking? I'm sorry if this still doesn't make sense. I've included a sample sheet of raw data from downloaded statements. Ideally, the Debits and Credits sheets should automatically update/refresh -- or at least do so with the click of a macro button-- each time I add new data to an existing table.

Sample Stmt Download.xlsx
EFGHIJKL
1Post DateReferenceAdditional ReferenceAmountDescriptionTypeClassText
26/1/2022 GE$29,166.67INCOMING WIRE TRANSFERWireMiscellaneous DepositGU
36/1/2022UKOGF FOUNDATION Payments $3.49ACH CREDITAchDevelopmentUKOGF FOUNDATION Payments
46/1/20225/3 BANKCARD SYS COMB. DEP. $275.50ACH CREDITAchBookstore5/3 BANKCARD SYS COMB. DEP. Worldpay
56/1/2022Virginia529 EDI PYMNTS $2,167.42ACH CREDITAchTuitionVirginia529 EDI PYMNTS
66/1/202253355335($2,290.99)CHECK PAIDCheckCheck
76/1/20226012215260122152($39,234.49)LOAN PAYMENTLoanLoan847,,AUTOMATIC LOAN PAY
86/2/2022Square Inc 220602P2 $48.25ACH CREDITAchEagles' WingsSquare Inc Bird Wings
96/2/2022Virginia529 EDI PYMNTS $1,100.00ACH CREDITAchTuitionVirginia529 EDI PYMNTS
106/2/2022SEMI MONTHLY FSA TRA($3,957.60)MISC. DEBITTransferFSASEMI MONTHLY FSA TRANSFER
116/2/2022WWEX Franchise H EP($277.54)PREAUTHORIZED ACH DEBITAchWWExWWEX Franchise
126/3/2022$103.46DEPOSITDepositDeposit
136/3/20223257-22 BB Merchan $67.66ACH CREDITAchBBMS3257-22 BB Merchan
146/3/2022AVIDPAY SERVICE AV($15.05)PREAUTHORIZED ACH DEBITAchAvidPay ACHAVIDPAY SERVICE AVIDPAY
156/3/2022GONZAGA COLLEGE MO($19,600.00)PREAUTHORIZED ACH DEBITAchACHGCHS
166/3/2022Voya Nat Trst182 SP($88,409.72)PREAUTHORIZED ACH DEBITAchPayrollVoya Nat Trst182
176/6/2022ACTIVE NETWORK, REGISTRATI $50,669.64ACH CREDITAchActive NetworkACTIVE NETWORK,
186/7/2022MERCHANTSERVCS BI($29.99)PREAUTHORIZED ACH DEBITAchBank FeesMERCHANTSERVCS BILLNG School Store
196/17/2022Square Inc 220617P2 $48.25ACH CREDITAchSquare DepositSquare Inc BirdWings
206/17/2022SMART LLC SMART LLC $37,287.31ACH CREDITAchSmart TuitionSMART LLC SMART LLC
06-2022 Daily Transactions
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
So, if I understand if the value in column H is positive copy this row to a sheet named Positive
And if the value in column H is negative copy this row to a sheet named Negative
But only copy the values in Column E, F, H and K
Is this correct?

If not give me all 3 sheet names.
And how do you expect to activate the script?
By clicking a button and copy all the rows in your sheet at the same time that meet the criteria?
Or when you double click on a cell in the row or enter a value in a cell on the sheet.
Please be specific with all your answers.
Say When I double click or enter a specific value in column G
Specifics are always important
And when we copy parts of this row to the other sheet do we delete the row from the original sheet?
 
Upvote 0
So, if I understand if the value in column H is positive copy this row to a sheet named Positive
And if the value in column H is negative copy this row to a sheet named Negative
But only copy the values in Column E, F, H and K
Is this correct?

If not give me all 3 sheet names.
And how do you expect to activate the script?
By clicking a button and copy all the rows in your sheet at the same time that meet the criteria?
Or when you double click on a cell in the row or enter a value in a cell on the sheet.
Please be specific with all your answers.
Say When I double click or enter a specific value in column G
Specifics are always important
And when we copy parts of this row to the other sheet do we delete the row from the original sheet?
Hello. You're on the right track. Here's more clarification:

Yes, if the value in column H is positive, copy the row to a sheet named Credits. If the value in column H is negative, its respective row would copy to a sheet named Debits. The original source sheet/tab is named 06-2022 Transactions.

Values in columns E through K would need to be copied (E, F, G, H, I, J, and K). Essentially, it would be the entire row, but I hid columns A-D because the info is immaterial and inconsequential.

As far as activating the script, pardon my ignorance, but do you mean via VBA/macros?
I'd like both the Credits and Debits sheets to have Refresh buttons, so that after I've entered new data (new lines) into the table on the original source sheet (06-2022 Transactions), I can go to those respective sheets, click their Refresh buttons, and the new entries will automatically appear based on column H's value.

No, nothing should be deleted from the original sheet when rows are copied to the new sheets. I have to retain original source information for audit purposes.

Please let me know if I'm lacking specifics. Thank you for taking the time to respond to my inquiry. I sincerely appreciate your time and assistance!
 
Upvote 0
You said:
As far as activating the script, pardon my ignorance, but do you mean via VBA/macros?
Sure, this must be done using a vba script.

And you said Refresh Button.
I do not know what a refresh button is.
I have been using Excel for years but do not know what you mean by refresh button.
Or do you mean when you click on a Button to run a script

And I asked:
And how do you expect to activate the script?
By clicking a button and copy all the rows in your sheet at the same time that meet the criteria?
Or when you double click on a cell in the row or enter a value in a cell on the sheet to copy just that row.
 
Upvote 0
You said:
As far as activating the script, pardon my ignorance, but do you mean via VBA/macros?
Sure, this must be done using a vba script.

And you said Refresh Button.
I do not know what a refresh button is.
I have been using Excel for years but do not know what you mean by refresh button.
Or do you mean when you click on a Button to run a script

And I asked:
And how do you expect to activate the script?
By clicking a button and copy all the rows in your sheet at the same time that meet the criteria?
Or when you double click on a cell in the row or enter a value in a cell on the sheet to copy just that row.
Thank you for your patience.

You're correct in regards to a Refresh button. In essence, a refresh button is simply a reload button to reload the page with updated data. In this case, the button name would simply be Refresh (instead of something like "Click Here" or "Reload"). When this button is clicked, it should run a script that pulls all the rows that meet criteria for the specific sheet (sheet named Credits pulls all rows with positive values in column H; sheet named Debits pulls all rows with negative values in column). Nothing from the original source sheet should be deleted as information is pulled into the other sheets. The best way I can put it is that the workbook should function similar to an advanced filter with automatic updates based on new information that is keyed in daily since I download bank transactions daily.
 
Upvote 0
Hello NewFrugal,

Assuming that your data is in an actual, formal Excel table, here's one option using only one button on the main sheet:-

VBA Code:
Option Explicit
Sub Test()

        Dim wsT As Worksheet, wsD As Worksheet, i As Long
        Dim ar As Variant: ar = [{"Debits","Credits";"<0",">0"}]
        Set wsT = Sheets("06-2022 Transactions")
        
Application.ScreenUpdating = False

        For i = 1 To UBound(ar, 2)
                     Set wsD = Sheets(ar(1, i))
                     wsD.UsedRange.Clear
                    
              With wsT.ListObjects("Table2").Range '---->Change table name to suit
                      .AutoFilter 8, ar(2, i)
                      .Columns("E:K").Copy wsD.[A1]
              End With
                      If wsT.FilterMode = True Then
                            wsT.ShowAllData
                      End If
              wsD.Columns.AutoFit
        Next i

Application.ScreenUpdating = True

End Sub

You'll just need to change the table name to suit. Assign the code to a button on your main sheet.
Please test the code in a copy of your actual workbook first.

I hope that this helps.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
Hello NewFrugal,

I've just changed the above code a little as the ShowAllData line may possibly error. The updated code is as follows:-
VBA Code:
Option Explicit
Sub Test()

        Dim wsT As Worksheet, wsD As Worksheet, i As Long, lo As ListObject
        Dim ar As Variant: ar = [{"Debits","Credits";"<0",">0"}]
        Set wsT = Sheets("06-2022 Transactions")
        Set lo = wsT.ListObjects("Table2") '---->Change table name to suit.
        
Application.ScreenUpdating = False

        For i = 1 To UBound(ar, 2)
                     Set wsD = Sheets(ar(1, i))
                     wsD.UsedRange.Clear
                    
              With lo.Range
                      .AutoFilter 8, ar(2, i)
                      .Columns("E:K").Copy wsD.[A1]
                      lo.AutoFilter.ShowAllData
              End With
              wsD.Columns.AutoFit
        Next i

Application.ScreenUpdating = True

End Sub

I've also declared a variable this time for the Listobject (Table2).

Cheerio,
vcoolio.
 
Upvote 0
Solution
Hello NewFrugal,

I've just changed the above code a little as the ShowAllData line may possibly error. The updated code is as follows:-
VBA Code:
Option Explicit
Sub Test()

        Dim wsT As Worksheet, wsD As Worksheet, i As Long, lo As ListObject
        Dim ar As Variant: ar = [{"Debits","Credits";"<0",">0"}]
        Set wsT = Sheets("06-2022 Transactions")
        Set lo = wsT.ListObjects("Table2") '---->Change table name to suit.
       
Application.ScreenUpdating = False

        For i = 1 To UBound(ar, 2)
                     Set wsD = Sheets(ar(1, i))
                     wsD.UsedRange.Clear
                   
              With lo.Range
                      .AutoFilter 8, ar(2, i)
                      .Columns("E:K").Copy wsD.[A1]
                      lo.AutoFilter.ShowAllData
              End With
              wsD.Columns.AutoFit
        Next i

Application.ScreenUpdating = True

End Sub

I've also declared a variable this time for the Listobject (Table2).

Cheerio,
vcoolio.
Hi, vcoolio. Thank you for responding. I tried assigning the code you provided to a button, but the Visual Basic editor keeps returning an error message. Please see the attached image. I don't really know what I'm doing when it comes to assigning the code to a button, but I've been under Design Mode trying to use an ActiveX control button.
 

Attachments

  • VBA Error.jpg
    VBA Error.jpg
    141.2 KB · Views: 6
Upvote 0
Hello NewFrugal,

I've just changed the above code a little as the ShowAllData line may possibly error. The updated code is as follows:-
VBA Code:
Option Explicit
Sub Test()

        Dim wsT As Worksheet, wsD As Worksheet, i As Long, lo As ListObject
        Dim ar As Variant: ar = [{"Debits","Credits";"<0",">0"}]
        Set wsT = Sheets("06-2022 Transactions")
        Set lo = wsT.ListObjects("Table2") '---->Change table name to suit.
       
Application.ScreenUpdating = False

        For i = 1 To UBound(ar, 2)
                     Set wsD = Sheets(ar(1, i))
                     wsD.UsedRange.Clear
                   
              With lo.Range
                      .AutoFilter 8, ar(2, i)
                      .Columns("E:K").Copy wsD.[A1]
                      lo.AutoFilter.ShowAllData
              End With
              wsD.Columns.AutoFit
        Next i

Application.ScreenUpdating = True

End Sub

I've also declared a variable this time for the Listobject (Table2).

Cheerio,
vcoolio.
You can disregard my last message to you. I figured out what I did wrong, and the coding now works. Thank you so much for your help!
 
Upvote 0
You're welcome NewFrugal. I'm glad to have been able to assist.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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