VBA help!

910 Views | 5 Replies | Last: 11 yr ago by BEaggie08
'03ag
How long do you want to ignore this user?
I have limited VBA knowledge. mostly I've been able to write a few macros from googling and hitting it with a hammer until it works.

I have a spreadsheet with nearly 400k lines. it's customer numbers, truck parts, their salesman, and their prices.

at a minimum what I need to do is split this file into separate tabs for each customer. this would be close to 60 tabs I'm guessing. in a perfect world I need to create a new file for each salesman(5 files) with each of their corresponding customers on separate tabs.

google hasn't been that much help, but I wonder if there's a certain function that should include in my search. I'm seeing a lot of stuff about creating/naming the sheets, but nothing about filling those sheets with the correct data.
Sentinel
How long do you want to ignore this user?
Ty this: http://pastebin.com/4fK7WxgJ
texagbeliever
How long do you want to ignore this user?
I'm sure Sentinel link is good. Only tough part will be understanding it so that you can make it useful.

How I would do it...

create 5 workbooks (or open up existing ones)
I would create a 2d array. That copies all 400k lines.
I would send have the code (if statements) determine whether to send each line to which workbook (by salesman done with a while or for loop)
Then which worksheet based on client or other criteria.
BEaggie08
How long do you want to ignore this user?
You probably don't want to hear this, but this should really be in a database. It would be much easier to maintain.
BlackGold
How long do you want to ignore this user?
I'm on pages 237 of vba for dummies. I'll get back to you when I finish.
'03ag
How long do you want to ignore this user?
I didn't think using if statements that way. Could be useful in the future.

I found a link similar to the one above and was able to make it work. I just have to run it twice basically.

Once to split the tabs by account manager. Move those tabs to their own file. Then run it again to split out by customer.

The data itself already came from a pretty nasty sql pull. It has to be emailed to the customers in excel so this seemed easier. I've never really put a lot of effort into, but emailing from access has always seemed like a pain to me.
BEaggie08
How long do you want to ignore this user?
Access sucks, but it will do whatever you build it to do. We run a subsidiary on Access and have a reporting section that easily exports selected to data into Excel.

To clarify, I wasn't saying that the answer to your question was to put all of this in Access. I was just saying it would be easier to manage if all of the info was in a database. It sounds like it is probably already in a database of some kind where it is managed if you're doing a sql dump to get the data you're working with now.

This is the basics of how I would attack the macro:
  • Clean up any inconsistencies or garbage in the import data (deleting blank rows or repeated headers, etc)
  • For Next Loop
  • Filter based on salesman to create a workbook
  • Filter based on each customer and copy/paste to create each worksheet within each salesman's workbook
  • Clear Filters
  • Next
I would use variables within the loop to define each salesman and each customer to make things easier.

Do the sales guys use this at summary level or detail level (are they looking for totals or line item detail)? I ask, because you could provide summary data via a pivot table pretty easily. Then, if the salesmen wanted additional detail they could double click on a subtotal in any section to get all of the detail that makes that data.
Refresh
Page 1 of 1
 
×
subscribe Verify your student status
See Subscription Benefits
Trial only available to users who have never subscribed or participated in a previous trial.