Help with VBA Code - Auto Move Into other Sheets

Mista_sav

Board Regular
Joined
Aug 18, 2019
Messages
69
Office Version
  1. 2016
Platform
  1. Windows
  2. Web
Hi There i currently have a code written by a kind gentleman on this site, and what it did was auto sort depending on the name of the status a loan was at. Then If a loan was funded or declined it would move it to the respective sheet in the work book. I now have multiple branches (Sheets) and when i copied it over i get an error. The original code is below and works fine

Private Sub Worksheet_Change(ByVal Target As Range)
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("Active_Loans")
Dim col As Range
Set col = Columns("G:G")
If Selection.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("G:G")) Is Nothing Then Exit Sub
Dim lr As Long, lr2 As Long
Application.EnableEvents = False
lr = Sheets("Loans Disbursed").Cells(Rows.Count, "G").End(xlUp).Row
lr2 = Sheets("Loans Declined").Cells(Rows.Count, "G").End(xlUp).Row
Select Case Target.Value
Case Is = "Disbursed"
Target.EntireRow.Copy
Sheets("Loans Disbursed").Rows("2:2").Insert
Target.EntireRow.Delete
Case Is = "Declined/Withdrawn"
Target.EntireRow.Copy
Sheets("Loans Declined").Rows("2:2").Insert
Target.EntireRow.Delete
End Select
With tbl.Sort
.SortFields.Clear
.SortFields.Add Key:=col, SortOn:=xlSortOnValues, Order:=xlDescending
.Header = xlYes
.Apply
End With
With Application
.EnableEvents = True
.CutCopyMode = False
End With
End Sub


but when i copied it i get this error see pic in uploads.

I think it has something to do with trying to replicate the code to other sheets. Is there anyway i can copy the code so it applies to any sheet i want. I tried renaming it to the sheet name but i get the runtime error 9 subscript out of range
 

Attachments

  • Error.png
    Error.png
    68.1 KB · Views: 9
  • Error 2.png
    Error 2.png
    69.8 KB · Views: 8

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Does the table "Active_Loans" exists?
Could you post a screenshot with that table?
 
Upvote 0
Does the table "Active_Loans" exists?
Could you post a screenshot with that table?
i have uploaded the sheet see attached. Basically i want the exact same sheet for every shop, and for it to run exactly the same as this one does.
 

Attachments

  • Example.png
    Example.png
    130.4 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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