Set a new range after searching for a value

jgeller

New Member
Joined
May 22, 2013
Messages
3
I am searching my entire worksheet for an account number, once I find that account number, I need to search again within a new range. The new range starts with the first cell i searched for (account number) and ends 45 rows down. How can I resize the range after I already searched? Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Can you post the code you have?

Generally to resize a range you would, surrpisingly, use Resize.

Code:
Set rng = Range("A1")

Set rng = rng.Resize(45) ' resize rng by 45 rows, rng now refers to AA1:A45
 
Upvote 0
Code:
Sub Macro()


Dim accountNumber As String




'USER INPUTS'
accountNumber = InputBox(Prompt:="What is the account number", _
          Title:="Account Name", Default:="ex: 3192-003")






'Search'
Sheets("Sheet1").Select 
Range("b1:b36675").Find(accountNumber).Select 'Search for  acc number

End Sub

Now with the selected cell, how can i search a new range from the selected cell and 45 rows down? Thanks

basically I want to search again, but this time instead of from "b1" it should be the new selected cell, and "b36675" should be "b1+45".
 
Last edited:
Upvote 0
Perhaps something like this.
Code:
Sub Macro()
Dim rngFnd As Range
Dim accountNumber As String

    'USER INPUTS'
    accountNumber = InputBox(Prompt:="What is the account number", _
                             Title:="Account Name", Default:="ex: 3192-003")
                             
    Set rngFnd = Sheets("Sheet1").Range("b1:b36675").Find(accountNumber)    'Search for  acc number

    If rngFnd Is Nothing Then
        MsgBox "Account number " & accountNumber & " not found."
    Else
        Set rngFnd = rngFnd.Resize(45).Find("Something")

        If Not rngFnd Is Nothing Then
            MsgBox "Something found in " & rngFnd.Address
        End If
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,603
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top