ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   maintaining the value of a variable outside of an if construct... (https://www.excelbanter.com/excel-programming/415700-maintaining-value-variable-outside-if-construct.html)

R Tanner

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

Jim Thomlinson

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



All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com