+ Reply to Thread
Results 1 to 4 of 4

Set range to every 7th cell

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Scotland
    MS-Off Ver
    10
    Posts
    37

    Question Set range to every 7th cell

    I currently used this code attached to a command button to search and find employees in my company by their surname
    although the row now includes both names and other details, is there a way I can still only search for the surname?

    The surname is in every 7th cell along (starting at E1... L1... S1 ect)
    Would there be any way to set the range for every 7th cell in the row ?

    Sub Find_Name()
    Dim intColumn As Integer
    Dim strBox As String
    Dim rFind As Range
    Dim intRow As Integer
    intRow = ActiveCell.Row
    
    strBox = InputBox("Enter the name you want to search for.")
    
    If strBox = "" Then Exit Sub
    
    Set rFind = Rows("1:1").Find(What:=strBox, LookIn:=xlValues, LookAt:=xlPart)
    
    If Not rFind Is Nothing Then
        rFind.Select
        intColumn = ActiveCell.Column
    Cells(intRow, intColumn).Select
    Else
        MsgBox ("That name could not be found")
    End If
    
    End Sub

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Set range to every 7th cell

    Hi justmegan,

    I believe the answer is yes, but would it be possible to see the sheet to understand a little better? You want the range to be every 7th cell in the row, but your range is the range where the name matched... so if you just select every 7th cell, does that not mean you are selecting all surnames?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Set range to every 7th cell

    Every 7th cell, I would just use a for...next with a step of 7


    for i = 1 to NUM step 7    '[NUM = total number of populated columns]
    'and offset to find that 7th column
    rfind = Range("a1").Offset(0, i)
    'code
    next i
    Or something along those lines
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  4. #4
    Registered User
    Join Date
    06-26-2014
    Location
    Scotland
    MS-Off Ver
    10
    Posts
    37

    Re: Set range to every 7th cell

    Private Sub FindName_Click()
    Dim intColumn As Integer
    Dim strBox As String
    Dim rFind As Range
    Dim intRow, i As Integer
    intRow = ActiveCell.Row
    
    strBox = InputBox("Enter the name you want to search for.")
    
    If strBox = "" Then Exit Sub
    
    For i = 1 To 900 Step 7
    Set rFind = Range("d2").Offset(0, i)
     Set rFind = rFind.Find(What:=strBox, LookIn:=xlValues, LookAt:=xlPart)
    If Not rFind Is Nothing Then
        rFind.Select
        intColumn = ActiveCell.Column
    Cells(intRow, intColumn).Select
    End If
    Next i
    End Sub
    Thank you Speshul
    Got it to work now!
    Last edited by Justmegan93; 03-16-2015 at 08:42 AM. Reason: Typo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 06-05-2014, 05:02 PM
  2. macro to find text string in cell range and paste in other cell range
    By slearner1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2013, 11:15 AM
  3. RE:- Write Macro to copy a 2 cell range to another 2 cell range down the columns
    By Eire001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2013, 11:48 PM
  4. copy a range of cell values to another range of cells if one cell = 1
    By jamiepullen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2008, 10:26 AM
  5. Change cell colour for a cell or range within a predefined range
    By Martin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2005, 02:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1