+ Reply to Thread
Results 1 to 5 of 5

Retrieving data from other excel sheets.

  1. #1
    Registered User
    Join Date
    11-15-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    9

    Retrieving data from other excel sheets.

    Hello, so I am what you would call a rookie at VBA-programming, nonetheless, I need to learn it! Currently I am trying to figure out a way to get certain cells from one excel sheet into another. I am using the code posted below:

    Sub GetValue()
    p = "xxx"
    F = "xxxx.xlsx"
    s = "xxxx"
    Application.ScreenUpdating = False
    For r = 1 To 100
    For c = 1 To 10
    a = Cells(r, c).Address
    Cells(r, c) = GetValue(p, F, s, a)
    Next c
    Next r
    Application.ScreenUpdating = True
    End Sub

    But this is generating very odd values. It only imports the cell-value in B2 and copies that value to cells A1, A2, B1 and B2. All other cells have #VALUE! error. I cannot understand this, hopefully you can help me!

    Best regards
    Pelle

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Retrieving data from other excel sheets.

    If I'm reading it right you're just trying to copy the range A1:J100 from one workbook to another? Is that correct?

    Please use code tags when posting code.

    Dom
    Last edited by Domski; 12-06-2010 at 07:10 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    11-15-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Retrieving data from other excel sheets.

    Yes I guess I am. But this is only the first step in what I want to do.
    I aim at retrieving data from one set of accounts based on a certain account number.
    E.g. there are 10000 different account numbers, but we only want to insert those with account numbers between 1-1000 in f.ex. the cell named "revenue" and 1001-2000 in another cell etc.

    My idea was that I needed to make a do loop, and then start by actually being able to get the numbers imported. After that I plan on adding if loops or something of the sort thereby achieving my goal.

    But, as I wrote above, my (very simple) code doesn't work properly, and I have no idea why.
    Thanks for your help,
    Pelle

    PS.
    I am using this "GetValue" function I found somewhere:
    Please Login or Register  to view this content.
    Last edited by PelleCadol; 12-06-2010 at 08:33 AM.

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Retrieving data from other excel sheets.

    That makes things a bit clearer. It's not a good idea to have subs and functions with the same name, in the same way that you should avoid defining anything as a reserved word.

    Looking at the function you just posted I think this line:

    Please Login or Register  to view this content.

    should just be:

    Please Login or Register  to view this content.

    I think the code you wrote should be fine after that although you should get used to declaring your variables at the beginning of the procedure like this:

    Please Login or Register  to view this content.

    I did a quick test and it pulled the values in fine from my file.

    Hope it helps,

    Dom

  5. #5
    Registered User
    Join Date
    11-15-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Retrieving data from other excel sheets.

    Thanks alot for the solution! It works perfectly now. I greatly appreciate the effort, Pelle

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1