Consulting

Results 1 to 7 of 7

Thread: column question

  1. #1
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location

    column question

    Hi,

    i'm downloading data that may be about 5000 rows or more &
    maximum 200 columns.
    is there a better way to code the columns?

    [vba]
    Rw = Rw + 1
    With Worksheets("EHMCR")
    .Cells(Rw, "A").Value = Field1
    .Cells(Rw, "B").Value = Field2
    .Cells(Rw, "C").Value = Field3
    .Cells(Rw, "D").Value = Field4
    .Cells(Rw, "E").Value = Field5
    ...etc...
    .Cells(Rw, "GR").Value = Field200
    End With
    [/vba]


    thanks
    zach

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What type of file are your getting your data from? Can you post a small sample?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Tutor
    Joined
    Feb 2006
    Posts
    295
    Location
    hi malcolm,

    i'm screenscraping data from a mainframe application using attachmate. each record may contain anywhere from 20 fields to 200 fields of data.
    i was getting tired of typing all the way up to column "GR":


    i was thinking something like this:
    [VBA]
    col = 0
    With Worksheets("test")
    .Cells(Rw, col).Value = Field1
    .Cells(Rw, col + 1).Value = Field2
    .Cells(Rw, col + 2).Value = Field3
    .Cells(Rw, col + 3).Value = Field4
    .Cells(Rw, col + 4).Value = Field5

    and so forth

    [/VBA]

    but that's still a lot of typing. i'm almost finished now...

    thanks for your thoughts on this
    zach

  4. #4
    If you are getting the input as some text or formatted file. You can try Query Table. That would be faster

    Once your Query Table is loaded you can delink it

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Unless I know more about the Fields, I can't really advise.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    Quote Originally Posted by vzachin
    hi malcolm,

    i'm screenscraping data from a mainframe application using attachmate. each record may contain anywhere from 20 fields to 200 fields of data.
    i was getting tired of typing all the way up to column "GR":
    [...]
    thanks for your thoughts on this
    zach
    Zach,

    So, please upload a wee sample of your screenscrapings; also, explain why (under what conditions) the data ranges between 20 and 200 columns.

    Thanks!

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If you can get your data in an array (1-based)

    Range(.Cells(rowNm,1),.Cells(rowNm,UBound(myArray))).Value=myArray
    is a quick way to write the array to the spreadsheet. Much quicker than looping.

    It also works with 2-dimensional arrays.

Posting Permissions

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