Error: Object variable or With block variable not set

G

Guest

I'm a new VBA programmer and cannot figure out what is wrong with the
following code. I get a Run-Time error '91' Object variable or With block
variable not set. Any assistance will help maintain my sanity. Thanks.


Sub BuildProjMap()
'********************************************************************************
'*
'* This Macro builds the Project Map range of dates based on the
'* number of weeks of duration for ADB + Test + Release.
'*
'********************************************************************************
' *************************************************
' Set initial variables
' *************************************************

rowProjDataStart = 4
rowProjDataEnd = 60
colProjMapDataStart = 17
colProjMapDataEnd = 46

colTargetRelWeekValue = 16
colADBDurValue = 14
colTestDurValue = 15

' ActiveSheet = "Sheet1"
SearchString = Cells(rowProjDataStart, colTargetRelWeekValue).Value
StartRow = 3
StartCol = colProjMapDataStart



colReleaseColNum = 35 ' replace this with a lookup
colADBStartColNum = colReleaseColNum - Cells(rowProjDataStart,
colTestDurValue) - Cells(rowProjDataStart, colADBDurValue)
colTestStartColNum = colADBStartColNum + Cells(rowProjDataStart,
colADBDurValue)




Sub SearchRows(ActiveSheet, SearchString, StartRow, StartCol,
TargetRowNumVarName)

'Sheets("ActiveSheet").Activate

Cells(StartRow, StartCol).Select

Cells.Find(what:=SearchString, after:=ActiveCell, LookIn:=xlValues, _
SearchOrder:=xlColumns).Activate
TargetRowNumVarName = ActiveCell.Row

End Sub
Sub SearchColumns(ActiveSheet, SearchString, StartRow, StartCol,
TargetColNumVarName)

'Sheets(ActiveSheet).Activate

Cells(StartRow, StartCol).Select
Cells.Find(what:=SearchString, after:=ActiveCell, LookIn:=xlValues, _
SearchOrder:=xlRows).Activate
TargetColNumVarName = ActiveCell.Column

End Sub
 
G

Guest

You throw up ~100 lines of code and don't say where the error is.

Here is a guess:

Instead of code like:
Cells.Find(what:=SearchString, after:=ActiveCell, LookIn:=xlValues, _
SearchOrder:=xlColumns).Activate
TargetRowNumVarName = ActiveCell.Row

use
Dim rng as Range
set rng = Cells.Find(what:=SearchString, after:=ActiveCell,
LookIn:=xlValues, _
SearchOrder:=xlColumns)
if not rng is nothing then
TargetRowNumVarName = rngl.Row
else
TargetRowNumVarname = 0
end if

This way when the SearchString is not found, it doesn't try to do
nothing.Activate and raise the error you describe.

Just a guess at your problem.
 
G

Guest

Thanks again for your help Tom. Sorry about not posting the source of the
error. You still managed to find the problem. No more errors!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top