For each loop does not loop

Roaldb

New Member
Joined
Feb 10, 2016
Messages
9
I have a procedure that calls other procedures from Personal workbook based on text string in cell A2.
It works perfect for the first sheet, but it wont loop the sheet. After the code runs for the first sht I get an "Application-defined or object-defined error.

what do I do wrong?


Sub TextToColumns()
Dim sht As Worksheet


For Each sht In ActiveWorkbook.Worksheets


If sht.Range("A2") Like "*NEW: NR255.P1BAIBKR.P190BEL.WRK03*" Then
Application.Run "Personal.xlsb!Felix310"


ElseIf sht.Range("A2").Value Like "*OLD: NR255.P1BAIBKR.P310BEL.MEL03*" Then
Application.Run "Personal.xlsb!KVH_310"


ElseIf sht.Range("A").Value Like "*OLD: NR255.P1BAIBKR.P190BEL.MEL02*" Then
Application.Run "Personal.xlsb!KVH_Felix"

End If

Next

End Sub
 

Some videos you may like

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,277
Office Version
  1. 365
Platform
  1. Windows
That will loop ok aside from one range saying "A" rather than "A2". It must be something to do with the called macro.
 

Roaldb

New Member
Joined
Feb 10, 2016
Messages
9
This is an example of one of the called macroes (made from macro recorder)
it will sort text in to clumns.

Range("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1), Array(4, 1), Array(18, 1), Array(30, 1)), _
TrailingMinusNumbers:=True
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Columns("D:D").Select
Selection.Delete Shift:=xlToLeft
Columns("B:B").Select
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("B1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:C96")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.NumberFormat = "0"

ActiveSheet.Name = "KVH FELIX"

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,915
Messages
5,598,850
Members
414,263
Latest member
sherrcha

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
Top