LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Loops stop working and presents "Run time error '91':

If I use a loop the runtime error presents itself showing "Object
variable or with block variable not set". This presents itself in the
"rng.Select" part of the code. Any suggestions why this occurs? I have
come around the problem using "On Error Resume Next". But I rather not
want to use that command... Any help is greately appreciated!

Sub Classification_Top_3()

TargetColumn = 1
TargetRow = 2
StartCell = "A1"
Sht = "SPI"
Sht2 = ActiveSheet.Name

SearchVariable2 = Sheets(Sht2).Range(StartCell).Value

Do While Not SearchVariable2 = ""
TargetRow = 2
Call Classification_Engine2

Sheets(Sht2).Select
Selection.End(xlUp).Select
ActiveCell.Offset(0, 1).Activate

SearchVariable2 = ActiveCell.Value
TargetColumn = TargetColumn + 1
Loop


End Sub

Sub Classification_Engine2()

Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlManual

Sheets(Sht).Select

' Finds Industry Column
SearchVariable = "INDUSTRY"
Call Find

IndustryColumn = OffsetColumn
NumberofComps = Sheets(Sht).UsedRange.Rows.Count

' Finds Subindustry Column
SearchVariable = "SUBINDUSTRY"
Call Find

SubIndustryColumn = OffsetColumn

' Finds Region Column
SearchVariable = "Region"
Call Find

RegionColumn = OffsetColumn

' Finds Region Column
SearchVariable = "Dscode"
Call Find

DscodeColumn = OffsetColumn

' Defines which columns to be used for concatenated ind/subind and
region
Worksheets(Sht).Range("C9").Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select

RegionandIndustryColumn = ActiveCell.Column
RegionandSubIndustryColumn = ActiveCell.Offset(0, 1).Column

' Copies the Dscode of the desired ranking firm to the output sheet
SearchRow = 9
For i = 1 To 3
Set rng = Nothing
Set rng = Cells.Find(What:=SearchVariable2, _
After:=Cells(SearchRow,
RegionandIndustryColumn), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

rng.Select
If Not rng Is Nothing Then
SelectRow = ActiveCell.Row
SelectColumn = DscodeColumn

Worksheets(Sht2).Cells(TargetRow, TargetColumn).Value = _
Worksheets(Sht).Cells(SelectRow, SelectColumn).Value

End If

SearchRow = SelectRow + 1
TargetRow = TargetRow + 1
Next i

End Sub


Sub Find()
Sheets(Sht).Select
SearchRow = 9
OffsetColumn = WorksheetFunction.Match(SearchVariable,
Rows(SearchRow), 0)
End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
stop error message "too many different cell formats" Judy Excel Worksheet Functions 1 May 7th 09 05:31 PM
Stop the "Personal" sheet from popping up every time I open a work George B Excel Discussion (Misc queries) 2 December 21st 07 10:46 PM
How do I stop "&T" in AT&T from displaying time in Excel footer? M. Harper Setting up and Configuration of Excel 2 April 29th 07 02:10 PM
Formulas stop working on all excell spreads at the same time exceltca Excel Worksheet Functions 3 July 26th 06 03:06 PM
Excel should STOP the "zero or negative ..in log plot" error msg HQDEARTHY Charts and Charting in Excel 1 February 9th 06 06:33 PM


All times are GMT +1. The time now is 11:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"