Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select current range of cells not whole row - Excel VBA

Posted on 2011-03-24
7
Medium Priority
?
767 Views
Last Modified: 2012-05-11
Hi Again
I am so sorry for annoying, but I need to get this up today.  I got Syd's fix working and have moved to another part of the spreadsheet (bearing in mind I didn't design this).  The range to look in starts at bf7 and across to ck.

I can get this to work, but don't want it to select the whole active row this time, just a range of cells.  So the line: workstn.Rows(c.Row).Select  I don't want to be the whole row.  I want it to start at column bf and move across to ck.

I really hope someone can help and please excuse my ignorance.  This really isn't my area.

Cheers and thanks
Private Sub cmbFind_Click()
    Dim strFind As String    'what to find
    Dim FirstAddress As String
    Dim rSearch As Range  'range to search
    Set rSearch = workstn.Range("bf7", Range("bf65536").End(xlUp))
   Dim f      As Integer
    strFind = Me.unmtxt.Value    'what to look for
     With rSearch
        Set c = .Find(strFind, LookIn:=xlValues)
        If Not c Is Nothing Then    'found it
        workstn.Rows(c.Row).Select
            With Me    'load entry to form
                .proftxt.Value = c.Offset(0, 1).Value
                .typetxt.Value = c.Offset(0, 2).Value
                .descritxt.Value = c.Offset(0, 3).Value
                .detailtxt.Value = c.Offset(0, 4).Value
                .versiontxt.Value = c.Offset(0, 5).Value
                .locationtxt.Value = c.Offset(0, 6).Value
                .cmbAmend.Enabled = True     'allow amendment or
                .cmbDelete.Enabled = True    'allow record deletion
            f = 0
            End With
            FirstAddress = c.Address
            Do
                f = f + 1    'count number of matching records
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> FirstAddress
            If f > 1 Then
                Select Case MsgBox("There are " & f & " instances of " & strFind, vbOKCancel Or vbExclamation Or vbDefaultButton1, "Multiple entries")

                    Case vbOK
                        FindAll
                    Case vbCancel
                        'do nothing
                End Select
                Me.Height = frmMax

            End If
                   
        Else: MsgBox strFind & " doesn't seem to be on the list. You may have to use a different name"    'search failed
        End If
    End With
    If workstn.AutoFilterMode Then workstn.Range("Bf9").AutoFilter
   End Sub

Open in new window

0
Comment
Question by:mjbdbase
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 35212388
Try this

rRow = workstn.Rows(c.Row)
range((Range("BF"&rRow),Range("CK"&rRow)).select

Cheers,

Dave
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35212394
or if you want to start in row 7, then go to the selected row of CK, then

rRow = workstn.Rows(c.Row)
range(Range("BF7",range("CK"&rRow)).select

Dave
0
 

Author Comment

by:mjbdbase
ID: 35212492
Ummm is there the bracket missing?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Accepted Solution

by:
mjbdbase earned 0 total points
ID: 35212706
Hope you don't mind, but I ended up "nutting" it myself.  Have posted the code below. It may be the long way of doing it, but should be ok for our needs.
In case anyone wanted clarification, the person who designed the spreadsheet put all of the info on one sheet.  I will change this one day but am time strapped with other work.  
The reason I wanted to select from the active cell which had been found, across to row CK was that I want the user to be able to delete rows and shift cells up without deleting WHOLE rows.

 c.Select
        Range(ActiveCell, ActiveCell.Offset(0, 31)).select

Thanks for the help though Dave. As always was prompt.

Cheers
Private Sub cmbFind_Click()
    Dim strFind As String    'what to find
    Dim FirstAddress As String
    Dim rSearch As Range  'range to search
    Set rSearch = workstn.Range("bf7", Range("bf65536").End(xlUp))
   Dim f      As Integer
    strFind = Me.unmtxt.Value    'what to look for
     With rSearch
        Set c = .Find(strFind, LookIn:=xlValues)
        If Not c Is Nothing Then    'found it
        c.Select
        Range(ActiveCell, ActiveCell.Offset(0, 31)).select
              With Me    'load entry to form
                .proftxt.Value = c.Offset(0, 1).Value
                .typetxt.Value = c.Offset(0, 2).Value
                .descritxt.Value = c.Offset(0, 3).Value
                .detailtxt.Value = c.Offset(0, 4).Value
                .versiontxt.Value = c.Offset(0, 5).Value
                .locationtxt.Value = c.Offset(0, 6).Value
                .cmbAmend.Enabled = True     'allow amendment or
                .cmbDelete.Enabled = True    'allow record deletion
            f = 0
            End With
            FirstAddress = c.Address
            Do
                f = f + 1    'count number of matching records
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> FirstAddress
            If f > 1 Then
                Select Case MsgBox("There are " & f & " instances of " & strFind, vbOKCancel Or vbExclamation Or vbDefaultButton1, "Multiple entries")

                    Case vbOK
                        FindAll
                    Case vbCancel
                        'do nothing
                End Select
                Me.Height = frmMax

            End If
                   
        Else: MsgBox strFind & " doesn't seem to be on the list. You may have to use a different name"    'search failed
        End If
    End With
    If workstn.AutoFilterMode Then workstn.Range("Bf9").AutoFilter
   End Sub

Open in new window

0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 35213162
Sorry. Just woke up. :)

What you are doing is the same as what dave suggested in post 1 :)

range((Range("BF"&rRow),Range("CK"&rRow)).select

and this

Range(ActiveCell, ActiveCell.Offset(0, 31)).select

are the same :)

Sid
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35219923
Thanks Sid.  mjbdbase - whatever - glad you nutted it.
0
 

Author Closing Comment

by:mjbdbase
ID: 35239207
Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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,…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

604 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