Results 1 to 7 of 7

Thread: Excel and VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    79

    Excel and VBA

    Hi all.
    I have a question here regarding MS Excel.
    I have a data (see VSM1.jpg) that I loaded from MS Access to MS Excel.
    Can VBA change the layout of the data in VSM1.jpg into VSM2.jpg?

    Thanks in advance.
    Attached Images Attached Images   

  2. #2
    New Member
    Join Date
    Sep 2005
    Posts
    1

    Re: Excel and VBA

    I dont think so.

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Excel and VBA

    You could.

    You might want to read up on pivot table first though...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    79

    Re: Excel and VBA

    How? Can u show me some example?

  5. #5
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Lightbulb Re: Excel and VBA

    Hi..

    If i understand correctly...this is what the code that helps u...

    Just select the cells that u want ...and say "Copy"..
    ofter run the fallowing code..

    VB Code:
    1. Range("a1").PasteSpecial xlPasteAll, xlPasteSpecialOperationNone, , True

    thanx & regards
    Anu.
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  6. #6
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Excel and VBA

    Hi,

    What nagasrikanth is actually saying there is to use the Transpose method - that is the purpose of the "True" in the pastespecial parameters. Transpose swaps rows and columns, but only when pasting. So, you'd need to copy the cells and paste using this.

    The alternative, if it was all to be done in a single workbook and you didn't want to get involved with cutting and pasting would be to stick it all in an array and then write it back out again. Slower for large grids, but pretty easy.

    VB Code:
    1. Dim myarray(3,3) as variant
    2.  for i = 1 to 3
    3.   for j = 1 to 3  
    4.    myarray(i,j) = cells(i,j)
    5.   next j
    6.  next i
    7.  
    8.  for i = 1 to 3
    9.   for j = 1 to 3  
    10.    cells(j,i) = myarray(i,j)
    11.   next j
    12.  next i

    You can make myarray as big as you like in rows and columns. You can't combine the loops because you're overwriting the same cells.

    HTH

    zaza

  7. #7
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Lightbulb Re: Excel and VBA

    thats good 'n' gr8 code by u zaza
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

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