Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default maintaining the value of a variable outside of an if construct...

Sub test()
Dim rng As Range
Dim x As Integer
Dim i As Range


Sheets("Workforce Data Table").Select
ActiveSheet.ListObjects( _
"WDT").Range. _
AutoFilter Field:=2, Criteria1:="Grave"

Range("A1").Select
Set RANGEENTRIES = Range("A1", ActiveCell.End(xlDown))
RANGEENTRIES.Select
Do While x <= NUMENTRIES
For Each cell In Selection
If ActiveCell.EntireRow.Hidden = False Then
x = x + 1
Set i = ActiveCell
Sheets("Monthly Management Report").Select
Range("B46").Select
ActiveCell.Cells(x, 0).Select

ActiveCell.Value = i
End If
i.Select 'This line fails, I'm assuming because my
variable i loses it's

'value outside of the if construct...
ActiveCell.Offset(1, 0).Select
Next cell
Loop

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default maintaining the value of a variable outside of an if construct...

i si still valid. you are trying to select a cell that is not on the active
sheet. Not going to work for you...

Sub test()
Dim rng As Range
Dim x As Integer
Dim i As Range


Sheets("Workforce Data Table").Select
ActiveSheet.ListObjects( _
"WDT").Range. _
AutoFilter Field:=2, Criteria1:="Grave"

Range("A1").Select
Set RANGEENTRIES = Range("A1", ActiveCell.End(xlDown))
RANGEENTRIES.Select
Do While x <= NUMENTRIES
For Each cell In Selection
If ActiveCell.EntireRow.Hidden = False Then
x = x + 1
Set i = ActiveCell
Sheets("Monthly Management Report").Select
Range("B46").Select
ActiveCell.Cells(x, 0).Select

ActiveCell.Value = i
End If
i.parent.select 'Select the sheet it comes from
i.Select
ActiveCell.Offset(1, 0).Select
Next cell
Loop

End Sub


--
HTH...

Jim Thomlinson


"R Tanner" wrote:

Sub test()
Dim rng As Range
Dim x As Integer
Dim i As Range


Sheets("Workforce Data Table").Select
ActiveSheet.ListObjects( _
"WDT").Range. _
AutoFilter Field:=2, Criteria1:="Grave"

Range("A1").Select
Set RANGEENTRIES = Range("A1", ActiveCell.End(xlDown))
RANGEENTRIES.Select
Do While x <= NUMENTRIES
For Each cell In Selection
If ActiveCell.EntireRow.Hidden = False Then
x = x + 1
Set i = ActiveCell
Sheets("Monthly Management Report").Select
Range("B46").Select
ActiveCell.Cells(x, 0).Select

ActiveCell.Value = i
End If
i.Select 'This line fails, I'm assuming because my
variable i loses it's

'value outside of the if construct...
ActiveCell.Offset(1, 0).Select
Next cell
Loop

End Sub

Reply
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
Public Variable not maintaining value. Mark Excel Programming 1 September 7th 05 07:16 PM
Maintaining cell 'variable' values even after the the macro has en tomwashere2 Excel Programming 1 August 18th 05 11:44 PM
if else construct Ian Bartlett Excel Worksheet Functions 2 July 22nd 05 01:16 PM
Maintaining VBA variable values Adam1 Chicago Excel Discussion (Misc queries) 3 March 14th 05 11:08 PM
How to construct for best speed? Stuart[_5_] Excel Programming 4 September 3rd 03 07:20 PM


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