?
Solved

Select current range of cells not whole row - Excel VBA

Posted on 2011-03-24
7
Medium Priority
?
761 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

801 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