Hi,
I need a macro to create a table with a size based on a formula and in which the values in the table are also formulas. An example is provided in attachment.
How can I do this?
Thanks
Last edited by Coaster; 05-08-2010 at 11:46 AM.
You will have to be more explicit in the details of what you are wanting to accomplish. Your attachment does not help to explain or clarify your post.
Please provide a more clear explanation and upload a revised attachment that includes an example of the results you want.
Palmetto
Do you know . . . ?
You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.
Thank you for your reply
I'm sorry I wasnt' clear, I think with this file things are more clear.
How critical is the "formula" part of this? Once you move to VBA, it's simpler to just put the values directly into the table.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
The thing is:
- input: data in a column (going up to 7000 rows or so)
- output: a table with that data organized the way it is in the excel file
The thing with the formula is that it is completely automatic. Putting the values directly into the table doesn't allow me to use the same code if the size of the table changes, for example.
See what I mean?
I was simply referring to the fact that once you move to VBA you can edit your "data" and rerun your macro to reassert your table at anytime, there's no need to maintain formulas in the table itself, it seems like plumbing you just don't need once you go to VBA.
This shows what I mean. I moved all the Input cells to the left so they do not interfere with a table size that could be any size. This will create the table starting in column H and go out as far as needed.
1) Put data in column B
2) Fill out the start, end and increments section
3) Click the button to create the table.
4) Change any of the inputs and click the button again to reassert the table
Option Explicit Sub CreateTable() 'Jerry Beaucaire 5/8/2010 'Take raw data and reformat into a 2D table Dim tbItm As Long Dim dataRNG As Range Dim vStart As Double: vStart = [D2] Dim vEnd As Double: vEnd = [E2] Dim vIncr As Double: vIncr = [F2] Dim hStart As Double: hStart = [D3] Dim hEnd As Double: hEnd = [E3] Dim hIncr As Double: hIncr = [F3] Application.ScreenUpdating = False If [I3] <> "" Then [I3].CurrentRegion.EntireColumn.Delete xlShiftToLeft Set dataRNG = Range("B2", Range("B" & Rows.Count).End(xlUp)) For tbItm = 1 To vEnd / vIncr + 1 Range("H2").Offset(tbItm, 0) = vStart + (vIncr * (tbItm - 1)) Next tbItm For tbItm = 1 To hEnd / hIncr + 1 Range("H2").Offset(0, tbItm) = hStart + (hIncr * (tbItm - 1)) Next tbItm vIncr = Application.WorksheetFunction.CountA(Range("H:H")) For tbItm = 1 To dataRNG.Cells.Count / vIncr Range("B2").Offset((tbItm - 1) * vIncr).Resize(vIncr).Copy Cells(3, Columns.Count).End(xlToLeft).Offset(0, 1).PasteSpecial xlPasteAll Next tbItm Set dataRNG = Nothing Range("I3").CurrentRegion.Columns.AutoFit Range("H:H").HorizontalAlignment = xlCenter Range("H2", Cells(2, Columns.Count)).HorizontalAlignment = xlCenter Application.ScreenUpdating = True End Sub
Last edited by JBeaucaire; 05-08-2010 at 11:34 AM.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
my god!
this is priceless, will save tons of time!
THANK YOU!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks