Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Performing a Macro within a range

I have unsucessfully tried to get this macro to stay within a range of a
worksheet ("E3:AU65535") to perform the following function/results. I have
columns of 0's with 1's and 2's in them. The 1 is a start date and the 2 is
an end date. I want to find each occurance and data fill with 1's inbetween
the 1's and 2's.

The rest of the worksheet should not be changed. I have tried several
different approaches....still looking....my find statement end up going
outside of the range. Can anyone help? Thanks...........

Sub FindOnes()

Dim DataWithOnes As Range
Dim Topcell As Variant
Dim Bottomcell As Variant

Set DataWithOnes = ActiveSheet.UsedRange

For Each c In ActiveSheet.UsedRange

Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 1 Then
Set Topcell = ActiveCell

Cells.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 2 Then
Set Bottomcell = ActiveCell

If Topcell = 1 Then Set Topcell = Topcell
Range(Topcell, Bottomcell).Select
Selection.FillDown
Bottomcell.Select

Set DataWithOnes = ActiveSheet.UsedRange


End If
End If

If DataWithOnes Is Nothing Then
GoTo done
End If
Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Performing a Macro within a range

hi
here is your problem.
For Each c In ActiveSheet.UsedRange
used range consists of all of the sheet that has data.
change that....
dim r as range
set r = activesheet.range("E3:AU65535")
for each c in r
....
i see usedrange in several place. change them too.

regards
FSt1

"Carrie" wrote:

I have unsucessfully tried to get this macro to stay within a range of a
worksheet ("E3:AU65535") to perform the following function/results. I have
columns of 0's with 1's and 2's in them. The 1 is a start date and the 2 is
an end date. I want to find each occurance and data fill with 1's inbetween
the 1's and 2's.

The rest of the worksheet should not be changed. I have tried several
different approaches....still looking....my find statement end up going
outside of the range. Can anyone help? Thanks...........

Sub FindOnes()

Dim DataWithOnes As Range
Dim Topcell As Variant
Dim Bottomcell As Variant

Set DataWithOnes = ActiveSheet.UsedRange

For Each c In ActiveSheet.UsedRange

Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 1 Then
Set Topcell = ActiveCell

Cells.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 2 Then
Set Bottomcell = ActiveCell

If Topcell = 1 Then Set Topcell = Topcell
Range(Topcell, Bottomcell).Select
Selection.FillDown
Bottomcell.Select

Set DataWithOnes = ActiveSheet.UsedRange


End If
End If

If DataWithOnes Is Nothing Then
GoTo done
End If
Next

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Performing a Macro within a range

Your are my hero....I have been stuck on this for days.......I never knew
that UsedRange applies to all data on the sheet. Makes perfect sense now.
Thanks!

"FSt1" wrote:

hi
here is your problem.
For Each c In ActiveSheet.UsedRange
used range consists of all of the sheet that has data.
change that....
dim r as range
set r = activesheet.range("E3:AU65535")
for each c in r
...
i see usedrange in several place. change them too.

regards
FSt1

"Carrie" wrote:

I have unsucessfully tried to get this macro to stay within a range of a
worksheet ("E3:AU65535") to perform the following function/results. I have
columns of 0's with 1's and 2's in them. The 1 is a start date and the 2 is
an end date. I want to find each occurance and data fill with 1's inbetween
the 1's and 2's.

The rest of the worksheet should not be changed. I have tried several
different approaches....still looking....my find statement end up going
outside of the range. Can anyone help? Thanks...........

Sub FindOnes()

Dim DataWithOnes As Range
Dim Topcell As Variant
Dim Bottomcell As Variant

Set DataWithOnes = ActiveSheet.UsedRange

For Each c In ActiveSheet.UsedRange

Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 1 Then
Set Topcell = ActiveCell

Cells.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
If ActiveCell.Value = 2 Then
Set Bottomcell = ActiveCell

If Topcell = 1 Then Set Topcell = Topcell
Range(Topcell, Bottomcell).Select
Selection.FillDown
Bottomcell.Select

Set DataWithOnes = ActiveSheet.UsedRange


End If
End If

If DataWithOnes Is Nothing Then
GoTo done
End If
Next

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
Performing Action on a Range of Rows JohnB[_2_] Excel Discussion (Misc queries) 1 July 20th 07 01:48 AM
Performing Action on a Range of Rows JohnB[_2_] Excel Discussion (Misc queries) 2 July 19th 07 06:22 PM
Performing a function on visible cells only in a range creative Excel Discussion (Misc queries) 2 April 9th 07 05:14 PM
Macro not performing Jim May Excel Programming 2 September 14th 05 02:39 AM
auto_open macro not performing as expected Eric Winegarner Excel Programming 1 April 19th 05 11:00 PM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"