Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Excel search Range

Posted on 2004-08-04
1
Medium Priority
?
264 Views
Last Modified: 2010-05-02
Hi - I have the following code that will open an Excel spreadsheet and return the values in Column A.  Let’s say that cell A1 is "boc ctgg-documentum", I want the program to then read a select range (C1:C3) and return the data in each cell.  Here’s the code that I have so far.  Any ideas?  Thanks for the help.

'------------------------------------------------------------------------------------------------------------------
Public Function CheckGroupInformation()
On Error Resume Next
   
    Dim xl As New Excel.Application
    Dim wb As Excel.Workbook
    Dim ws As Excel.Worksheet
   
    Set wb = xl.Workbooks.Open(txtPath.Text)
    Set wb = xl.Workbooks.Open(strGroupDrive)
    Set ws = wb.Worksheets("Group")

    'counts the number of rows within the workbook
    wb.Application.ActiveCell.SpecialCells(xlCellTypeLastCell).Select
    strCells = wb.Application.ActiveCell.Row
       
    'loop that gets name & then creates folders
    For r = 1 To strCells
        x = ws.Cells(r, 1)
               
        strGroupName = x
        Call CheckUserName
   
        For Each x In strCells
            If x = "boc ctgg-documentum" Then
                For Each y In strCells
                    y = ws.Range("C1")
                    Debug.Print y
                Next y
            End If
               
            Call MembersOfGroup(strGroupName, "mycompany.net", strUserName)
             
            If strGroupMembers = "1" Then
                ws.Cells(r, 2).Value = "Is a member"
                ws.Cells(r, 2).Font.Bold = True
                ws.Cells(r, 2).Font.Color = vbBlue
            End If
        Next x
    Next r
   
    'cleanup
    wb.Application.Workbooks(1).Save
    wb.Close
    xl.Quit
   
    cmdMoveFiles.Visible = False
    cmdDone.Visible = True
   
    Set wb = Nothing
    Set xl = Nothing
   
End Function
'------------------------------------------------------------------------------------------------------------------
0
Comment
Question by:eciabattari
[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
1 Comment
 
LVL 3

Accepted Solution

by:
kay2g earned 2000 total points
ID: 11730050
I think there may be a problem where you start to loop to get names and create folders. I think you are starting too many loops that cycle through nothing. strCells as declared in your program is a Long for all I know (I also dont know the contents of the CheckUserName procedure, so revealing that would help indeed). If strCells is a Long for what I know, it cannot be cycled using the For Each command since it is not a collection of some sort. Take a look at this snippet:

'loop that gets name & then creates folders
    For r = 1 To strCells
        x = ws.Cells(r, 1)
               
        strGroupName = x  
        Call CheckUserName
       
         'I think here lies the problem    
         If x = "boc ctgg-documentum" Then
                y = ws.Range("C1:C3")
                Debug.Print y
         End If
               
         Call MembersOfGroup(strGroupName, "mycompany.net", strUserName)
             
         If strGroupMembers = "1" Then
             ws.Cells(r, 2).Value = "Is a member"
             ws.Cells(r, 2).Font.Bold = True
             ws.Cells(r, 2).Font.Color = vbBlue
         End If

    Next r

I hope this helps

Kay
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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