Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Run-Time error '91': Object variable of With block variable not set | Excel Programming | |||
Run-time Error'91: Object variable or With block variable not set | Excel Programming | |||
Run-time error '91': "Object variable or With block variable not set | Excel Programming | |||
Cells.Find error Object variable or With block variable not set | Excel Programming | |||
Pivot Table - Object variable or with block variable not set? | Excel Programming |