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: 1
Default Object Variable with Block Variable Not set


I am a raw beginner at VBA and programming in general.
It need some help understanding where to place variables and how to
declare
them.

Please help me with this.
I have this code that changes a cell's text color, when I click a
transparent
label that is placed over the cell. There is a timer sub that delays
the code
and then allows another sub call *The_Sub()* to change the cell color
back.

There are 30 cells like this and enventually the code will be swapping
ranges

The code runs fine except for having *The_Sub()* recognize a variable
that is created in the main sub that is called *ManualSwap*
__________________________________________________ _______________
Public RunWhen As Double
Public FirstButtonPress As Integer
Public Const cRunIntervalSeconds = 4 '4 seconds
Dim FirstTeamNameCell As Range
Public Const cRunWhat = "The_Sub"
__________________________________________________ _______________

Public Sub ManualSwap(x As Integer)
Dim CrosstableCorner As Range
Set CrosstableCorner = Range("Crosstable_Corner")
If FirstButtonPress = 0 Then
FirstButtonPress = x
'Dim CrosstableCorner As Range
'Set CrosstableCorner = Range("Crosstable_Corner")
x = x - 1

Dim FirstTeamNameCell As Range
Set FirstTeamNameCell = Range(CrosstableCorner.Offset(x * 1 + 1, 0),
CrosstableCorner.Offset(x * 1 + 4, 0))
Dim FirstTeamRange As Range
Set FirstTeamRange = Range(CrosstableCorner.Offset(x * 1 + 1, 0),
CrosstableCorner.Offset(x * 1 + 4, 60))
*FirstTeamNameCell.Font.Color = RGB(255, 0, 0)*



'give the user 4 seconds to choose the second range in the swap
StartTime


Else

x = x - 1
Dim SecondTeamNameCell As Range
Set SecondTeamNameCell = Range(CrosstableCorner.Offset(x * 1 + 1, 0),
CrosstableCorner.Offset(x * 1 + 4, 0))
Dim SecondTeamRange As Range
Set SecondTeamRange = Range(CrosstableCorner.Offset(x * 1 + 1, 0),
CrosstableCorner.Offset(x * 1 + 4, 60))
'There are now 2 variables for the 2 ranges
'run some code here to swap the ranges
'set the to FirstButtonPress = 0 ready for the next swap
FirstButtonPress = 0


StopTimer
SecondTeamNameCell.Font.Color = RGB(255, 0, 0)
End If
'run some code with a short delay here to change both cells fonts back
to original color

End Sub
__________________________________________________ ______________
Sub The_Sub()
'Dim FirstButtonPress As Integer


FIRSTTEAMNAMECELL.FONT.COLOR = RGB(255, 204, 0)

_'Range(\"D6:D7\").Font.Color_=_RGB(255,_204,_0).. ._works in changing
the font color back, so the timer executes as intended but when I try
this using the variable _FirstTeamNameCell_ from the _ManualSwap_ I
can't get this sub to recognize it


End Sub
__________________________________________________ _______________
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, _
schedule:=True
End Sub
__________________________________________________ _______________
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedu=cRunWhat, schedule:=False
End Sub
__________________________________________________ _______________


*I appreciate any help in understanding how to correctly use
variables so they will be recognized in other subs.*


--
SuitedAces
------------------------------------------------------------------------
SuitedAces's Profile: http://www.excelforum.com/member.php...o&userid=35840
View this thread: http://www.excelforum.com/showthread...hreadid=557356

 
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
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Run-time Error'91: Object variable or With block variable not set DynamiteSkippy Excel Programming 4 September 26th 05 07:47 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 08:57 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"