Excel VB question

misterb

New member
Excel VB question

I made an Excel workbook that has a pivot table, and a button with a code that lets you select a CSV (text) file to be used as the new data for the pivot. The pivot data is located in a sheet in the workbook, and referenced by a range name. my code is doing it in a primitive way, which is : delete the old data range open the CSV file. copy all paste in "data" sheet redefine "data" range close CSV file This works OK as long the CSV file is small, when I get to above 10k lines, it takes him a long time to process. what is the better way to do it ?
 

AO

New member
Could you please send the code.

And Let us know if you can read Hebrew. Alon
 

misterb

New member
I can read hebrew, code attached

thanks for the quick response, the code is partial of course, only the relevant part.
 

AO

New member
רעיון...

אתה אומר שהבעיה מתעוררת רק בקבצים ארוכים. תנסה לבודד כל חלק מהמאקרו כדי למדוד זמנים. תמדוד זמנים לחלק שפותח את קובץ הנתונים בניפרד לחלק שמחליף את נתונים בקובץ הראשי בניפרד ולחלק שמרענן את טבלת הציר בנפרד. אם הגליון כולל חישובים רבים יתכן שזה נובע מחישובים שמתבצעים תוך כדי כל פעולה. תנסה להוסיף בתחילת המאקרו שורה שמעבירה את הקובץ לחישוב ידני (בניגוד לאוטומטי) ובסוף המאקרו תחזיר לחישוב אוטומטי אם תרצה או שתלחץ F9 בעצמך. תעדכן מה קורה ? אלון
 

misterb

New member
test results :

I checked, the biggest time consuming part is pasting the data range in the book, which took about 30 minutes for pasting ~15k lines (!), but when I do it manualy, it takes few seconds (2-3). any suggestions ?
 

AO

New member
???

ניסיתי מאקרו דומה שיש לי. הרצתי אותו על קובץ נסיוני של 12000 שורות ו 10 עמודות. פעם עם חישוב ידני ופעם אוטומטי (למרות שאצלי אין הרבה חישובים בקובץ הנסיוני). פעם סגרתי את הקובץ לפני ההדבקה ופעם אחרי ההדבקה. בכל אחד מהמקרים הפעולה ארכה כ 45 שניות. אין לי מושג מה הבעיה אני יכול רק להציע נסיונות . חישוב ידני במקום אוטומטי. במקום CURRENTREGION תנסה לקבוע בדיוק את הטורים שצריך להעתיק. במקום PASTESPECIAL הדבקה רגילה. אם יהיה לי רעיון אחר אכתוב לך. אלון
 

misterb

New member
got it !!!

thanks a lot, I found the problem : after copying the data, there a line to close the file, which by default copies the copy buffer to clipboard to be available to other apps.this is the part that takes a lot of time (copy all the data to outside clipboard), so I just added a line which copies one cell contents, so the buffer is small, and this solved it.
 

AO

New member
טוב לשמוע

דוקא חשבתי שהבעיה יכולה להיות בכיוון הזה וניסיתי להעביר את השורה שסוגרת את הקובץ לחלק שאחרי ההדבקה (כלומר קודם הדבקה ורק אח"כ לסגור את הקובץ) אבל זה לא שינה את הזמנים - אולי מכיוון שאצלי ממילא הם לא היו כ"כ ארוכים כמו אצלך ? (האם אתה עובד עם MAC ?) בכל אופן -
אלון
 
למעלה