Solved

Select current range of cells not whole row - Excel VBA

Posted on 2011-03-24
7
725 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
  • 3
  • 3
7 Comments
 
LVL 41

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 41

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 41

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now