Consulting

Results 1 to 10 of 10

Thread: first read from A1 then from B1 and so on

  1. #1
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location

    first read from A1 then from B1 and so on

    Guys I need help. I have xls file which has computer name in column A and office number in column B. Now I can read computer name and store value to variable str computer how can I simultaniousely read the value in B cell (office nr.) and store it into variable

    [VBA]Set objExcel = CreateObject("Excel.Application")
    'Gets the directory where our script is running from
    'Open our XLS file
    Set Workbook = objExcel.Workbooks.Open("C:\read registry\Machines.xls")
    'We want to skip the header row, and then the blank row below
    loopCount = 1
    Do While Not IsEmpty(objExcel.Cells(loopCount, 1).Value)
    Dim i 'For looping through the columns on each row
    Dim strComputer
    For i = 1 To 1
    strComputer = objExcel.Cells(loopCount, i).Value
    loopCount = loopCount + 1
    Next
    Loop[/VBA]

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]


    Set objExcel = CreateObject("Excel.Application")
    Dim i 'For looping through the columns on each row
    Dim strComputer As String
    Dim strOffice As String
    'Gets the directory where our script is running from
    'Open our XLS file
    Set Workbook = objExcel.Workbooks.Open("C:\read registry\Machines.xls")
    'We want to skip the header row, and then the blank row below
    loopCount = 1
    Do While Not IsEmpty(objExcel.Cells(loopCount, 1).Value)
    strComputer = objExcel.Cells(loopCount, "A").Value
    strOffice = objExcel.Cells(loopCount, "B").Value
    loopCount = loopCount + 1
    Loop
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    thnx man I'll try it now, and will let you know

  4. #4
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    It works perfectly, and I have another question

    I put value from registry into variable and it looks like this : MICKA, MICKOVA

    How do I separate first and last name or replace comma with tab character so when I write this value to cell the first and last name will be in separate cells in C and D not just in C

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim sName As String
    Dim aryNames As Variant

    sName = "MICKA, MICKOVA"
    aryNames = Split(Replace(sName, " ", ""), ",")
    Range("H1:H2") = Application.Transpose(aryNames)
    Range("M1:N1") = aryNames
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    [vba]
    Dim sName As String
    Dim aryNames As Variant
    'myString = "Micka, mickova"
    sName = myString
    aryNames = Split(Replace(sName, " ", ""), ",")
    Range("H1:H2") = Application.Transpose(aryNames) -waht does this do ????
    Range("M1:N1") = aryNames - what does this do ????
    [/vba]

    I have a problem getting also first name then I would like to have first and last name

    like this:
    mystring1 = Micka
    Mystring2 = Mickova

    Are those lines necesary
    [VBA]
    Range("H1:H2") = Application.Transpose(aryNames) -waht does this do ????
    Range("M1:N1") = aryNames - what does this do ????
    [/VBA]
    Any ideas
    Thnx

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You said you wanted to put them in cells, I showed you how.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    Yes man I appreciate that very much

    but how would i get from :
    mystring = "MICKA,, Mickova"
    mystring(0) = "MICKA"
    mystring(1) = "Mickova"

    Thnx man I really apprreciate your help

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is exactly what this bit does

    [vba]

    Dim sName As String
    Dim aryNames As Variant
    sName = "MICKA, MICKOVA"
    aryNames = Split(Replace(sName, " ", ""), ",")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  10. #10
    VBAX Mentor
    Joined
    Jan 2006
    Posts
    348
    Location
    but aryNames contains only MICKA which variable holds MICKOVA
    apart from that it works great

Posting Permissions

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