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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
That will loop ok aside from one range saying "A" rather than "A2". It must be something to do with the called macro.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,073
Members
449,205
Latest member
Healthydogs

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