+ Reply to Thread
Results 1 to 18 of 18

Grab data related to array code

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Grab data related to array code

    Hello everyone
    I have the following wonderful of HSV that enables me to transfer data across rows to columns
    Here's the attachment illustrating the expected results

    Please Login or Register  to view this content.
    I can get results in sheets("Result") starting in range("D2")
    In Sheets("Result") Columns A & B & C I need to fill the data from Sheets("Data")
    The data which will be grabbed related to each row
    for example : the data Yasser1 to Yasser7 which is in row 2 related to the date : 01/06/2015 so in the sheets("Result") column A .. Range("A2:A8") is expected to that date
    The same with the "Branch Column" data >> will be in range("B2:B8") and "Sort Column" data >> will be in range("C2:C8")

    Hope it is clear

    Thanks advanced
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Data Across Rows To Columns HSV - modified.xlsm

    YasserKhalil,

    Do you mean like this??

    (Please see attached spreadsheet.)


    - Ed

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Thanks a lot Mr. Ed_Collins for this great results
    When applying it to original file it tooks about 20 seconds to execute (5000 rows)
    So I was searching for editing the array code posted in Post #1 if possible .. or at least create a sub routine to complete the task of the first code
    Generally your code is really amazing

  4. #4
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Thanks.

    Put

    Application.ScreenUpdating = False

    at the very top of the code and

    Application.ScreenUpdating = True

    at the very bottom of the code. Rerun it and tell me how long it takes to execute with this change.


    If it still takes longer than what you want, we can tweak it to improve speed. I wasn't aware you had 5,000 rows of data.
    Last edited by Ed_Collins; 06-08-2015 at 12:05 AM.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Thanks for guiding me . I already put these lines before and after the code even before you prompt me .. disable events and make calculations manual and disable sceen updating
    But it still takes 15 seconds ..
    I prefer using arrays as the data may be larger in the future

  6. #6
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Try this code on your data.

    It takes less than a second on my machine, with more than 5,000 rows of test data.

    Please Login or Register  to view this content.
    It's basically the same code as before. But this time, instead of writing the data to the Cells, I'm just temporarily saving it to an array. Then I put the entire array where it needs to be, all at once.

    EDITED to correct a minor mistake.
    Last edited by Ed_Collins; 06-08-2015 at 02:25 AM.

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Thank you very much Mr. Ed_Collins
    you're really wonderful .. Just a little point if it won't disturb you ..
    Not to transfer data in row if the date in column A is empty .. In other words to check the existence of the date in column A .. if found the details in that row to be transferred and if not the data related to that ro not to be transferred
    Thanks advanced
    I appreciate your time and your great help

  8. #8
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Try this.

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Thank you very much for this wonderful code
    You are really fantastic

    Just a little remark
    The format of the dates are different from Data sheet & Results sheet ..
    How to fix it ??
    Just point me guide me .. Don't post the whole code again ..I will modifiy that point if you just guide me to the line
    Thanks for your time and effort

  10. #10
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    I'm not sure why the formatting is different. Maybe it's because my default format is different than yours, and when I saved the file it saved it in my format.

    If you select the entire column, and then right-click and choose FORMAT CELLS, and then select DATE, you can select the way you'd like to see it. Note that you may have to select your own specific location, in the second drop-down box.

    OR, you can simply paste my macro code into your own, original spreadsheet, and not the one I initially sent back to you. My code certainly doesn't change any formatting.

  11. #11
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    This is not the problem sir
    The dates are reversed in other words
    2 - 5 - 2015 this mean 2 May 2015
    After transfering it became
    5 - 2 - 2015 this means 5 February 2015

    the problem is not the format but it is reversed dates
    Attached Files Attached Files
    Last edited by YasserKhalil; 06-08-2015 at 12:52 PM.

  12. #12
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    I'll have to think about why this is happening. It shouldn't happen... the code simply grabs the data and holds it in an array and then copies it to the other sheet.

    When I open up your original work book, from Post #1, I see the four dates in the DATA worksheet as 6/1/2015, 6/4/2105, 6/2/2105, and 6/3/2015.
    And when I run my macro, and look at the results, the dates are in this same format. So at my end there is no problem.

    Again, not sure what is wrong at your end but I will think about it. I'm sure it's something easy... some type of a formatting issue.

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Mr. Ed_Collins
    Look at the attachment in post #11

  14. #14
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Copy your date format from the DATA worksheet into the RESULTS worksheet, to confirm the format is the same.

    Run the macro. The format should not change after the macro is run.
    Last edited by Ed_Collins; 06-08-2015 at 12:56 PM.

  15. #15
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    I don't see an attachment in post #11.

  16. #16
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    Thanks. I see the attachment now.

    When I run the macro on that file, the formatting does not change. It looks like this

    "Monday, June 01, 2015"

    on the DATA worksheet and it looks the same after the macro is run, on the RESULT worksheet.

  17. #17
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: Grab data related to array code

    All dates are really just numbers. It's the number of days after January 1, 1900, if I remember. And they can be formatted in a variety of different ways. The macro doesn't change the formatting. It just copies the number (formatted as a date) into an array and then copies it back again. I really can't figure out why your formatting is changing. Yes, you say at your end it's "reversed," but that's just a different way of formatting the date. (That's how some countries format it. dd-mm-yyyy instead of mm-dd-yyyy.)

  18. #18
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Grab data related to array code

    Thanks a lot Mr. Ed_Collins for following up my problem
    I don't know why this problem happened ..
    I have backup of my original file and I restored my backup and tested your last code again and found it working well without any problems...
    That's weird but it is solved
    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Code to grab data give critiria in textbox and output data range to cell range. Help!?
    By exclusiveicon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2014, 05:31 PM
  2. VB code for Excel to Open second spread sheet, grab data and close.
    By qi86@hotmail.co.uk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-07-2014, 04:59 AM
  3. Need to pull data based on related code
    By MReitz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-23-2011, 04:51 PM
  4. VBA code to populate data related to drop down list
    By ExcelGyan in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 10-04-2011, 03:32 AM
  5. [SOLVED] Need help on an issue related with code management & data dimension
    By J_J in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2005, 09:06 AM

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