Solved

Select current range of cells not whole row - Excel VBA

Posted on 2011-03-24
7
738 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 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 

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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

856 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