Solved

limit search in code

Posted on 2011-09-29
4
158 Views
Last Modified: 2012-05-12
Hi I have a piece of code StephenJR kindly provided me, i am looking for a slight amendment.

instead of searching the entire column (10) i would like it to stop at Row 10,000

Thanks
Seamus
Sub x()
  
Dim rFind As Range, sAddr As String
 
With Sheet1.Columns(10)
    Set rFind = .Find(What:="Sel", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
    If Not rFind Is Nothing Then
        sAddr = rFind.Address
        Do
            rFind.Offset(, 5) = -1 * rFind.Offset(, 5)
            Set rFind = .FindNext(rFind)
         Loop While rFind.Address <> sAddr
    End If
End With
     
End Sub

Open in new window

0
Comment
Question by:Seamus2626
  • 2
  • 2
4 Comments
 

Author Comment

by:Seamus2626
ID: 36814982
Or even better, if the code counted Column A and used that as its indicator to how many rows to search...........
0
 
LVL 24

Expert Comment

by:StephenJR
ID: 36815145
Seamus - try this:

With sheet1.range("J1",sheet1.range("J" & rows.count).end(xlup))
0
 
LVL 24

Accepted Solution

by:
StephenJR earned 500 total points
ID: 36815149
That should be:

With sheet1.range("J1:J" & sheet1.range("A" & rows.count).end(xlup).row)
0
 

Author Closing Comment

by:Seamus2626
ID: 36815203
Perfect, thanks Stephen!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question