Results 1 to 3 of 3

Thread: Array a cell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    208

    Array a cell

    hi there i have a cell [11] which contains "admingroup,update,viewonly" and it is a variable length. So one user can be in different user groups. i'm using an array to split the cell, however i'm only getting the first data (admingroup). here is the code i'm using. thank you in advance

    Private Sub CommandButton1_Click()

    Dim participant, password, userName, companyName, email, DTime As String
    Dim plantList As String
    Dim userGroup As String
    Dim myString As String
    Dim myArray As Variant
    Dim irow, icol As Integer
    Dim ifh As Long

    DTime = CStr(Now())
    DTime = Replace(DTime, "/", "-", 1, -1, vbTextCompare)
    DTime = Replace(DTime, ":", "-", 1, -1, vbTextCompare)
    DTime = Replace(DTime, " ", "-", 1, -1, vbTextCompare)

    ifh = FreeFile
    FileName = ActiveWorkbook.Path & "\Current_Export Users" & DTime & ".txt"
    Open FileName For Output As ifh

    irow = 3
    With ActiveSheet
    On Error Resume Next
    While .Cells(irow, 1) <> ""

    myString = .Cells(irow, 11)
    myArray = Split(myString, ",")

    icol = 1
    While .Cells(2, icol) <> ""

    ' Users

    userGroup = myArray(0)

    participant = .Cells(irow, 1)
    password = .Cells(irow, 2)
    userName = .Cells(irow, 3)
    email = .Cells(irow, 4)

    Print #ifh, "----------------------"
    Print #ifh, "User Group "
    Print #ifh, "----------------------"
    Print #ifh, "." & userGroup
    Print #ifh, "..UserGroupName|" & userGroup
    Print #ifh, "..UserGroupDesc|"
    Print #ifh, "----------------------"
    Print #ifh, "Export Users"
    Print #ifh, "----------------------"
    Print #ifh, ""
    Print #ifh, ".Usr"
    Print #ifh, "..Participant|" & participant
    Print #ifh, "..Password|" & password
    Print #ifh, "..UserName|" & userName
    Print #ifh, "..CompanyName|"
    Print #ifh, "..Email|" & email
    Print #ifh, "-------- END-----------"

    icol = icol + 1
    Wend
    irow = irow + 1
    Wend
    End With
    Close ifh
    End Sub
    Last edited by Prav; Nov 17th, 2005 at 01:08 AM.

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Array a cell

    probably better to use the Left, Right and InStr commands. heres one to get you started:

    VB Code:
    1. Group = Left(Range("B4"), InStr(Range("B4"), ",") - 1)
    if you fail to plan, you plan to fail

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Array a cell

    Prav
    Split will work fine here, but you haven't declared the array properly.

    Change
    Dim myArray As Variant
    to
    Dim myArray() As Variant
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width