Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Complex macro - Any ideas would be great

HI all,

I am strugling to produce the bellow functionallity for a reporting
system.

I have a main workbook ('Invoice') which contains invoice numbers, i
needs to look up data in several other workbooks
('January','Febuary','March'), consolidate the data corrosponding to a
certain invoice, then import it into a sheet in the main workbook.

EXAMPLE:

Workbook 'Invoice', sheet 1:

Invoice Number | Lookup Workbook
2 January
3 Febuary
4 March
5 Febuary
6 January


Workbook 'Febuary', sheet 1:

Invoice Number | Amount
3 10
3 30
3 15
5 50
5 30

FINAL Desired Result in Workbook 'Invoice', sheet 2

Invoice Number | Amount
3 55
5 80

Hope that makes sense. This is obvoicesly a simple example, in real i
need to import many other fields for thousands of records.

Realy hope someone can help me.

Kind Regards,



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default Complex macro - Any ideas would be great

Gareth.Evans wrote:
HI all,

I am strugling to produce the bellow functionallity for a reporting
system.

I have a main workbook ('Invoice') which contains invoice numbers, i
needs to look up data in several other workbooks
('January','Febuary','March'), consolidate the data corrosponding to a
certain invoice, then import it into a sheet in the main workbook.

EXAMPLE:

Workbook 'Invoice', sheet 1:

Invoice Number | Lookup Workbook
2 January
3 Febuary
4 March
5 Febuary
6 January


Workbook 'Febuary', sheet 1:

Invoice Number | Amount
3 10
3 30
3 15
5 50
5 30

FINAL Desired Result in Workbook 'Invoice', sheet 2

Invoice Number | Amount
3 55
5 80

Hope that makes sense. This is obvoicesly a simple example, in real i
need to import many other fields for thousands of records.

Realy hope someone can help me.

Kind Regards,




Have a look at Debra Dalgleish's explanation of the technique he

http://www.contextures.com/xlFunctions05.html#RefWkbk
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Complex macro - Any ideas would be great

several possible solutions come to mind - "there's more than one way to skin
a cat" - sorry cat people ;)

however, it depends on how many records you have

also, in your Invoice sheet, will an invoice number only have the one month
as per your example?

my first suggestion would be to bring all the data from the January -
December worksheets into one sheet in the invoice workbook, and then you can
just use the SUMIF function.

the following code should be pasted into a code module

Option Explicit
Sub RefreshData()
Dim mnth As Long ' index for monthly workbooks
Dim sfile As String ' "root" file name - January, February etc
Dim sfilename As String ' full filename if found eg January.xls
Dim wb As Workbook ' object for the monthly workbook
Dim source As Range ' data from monthly book
Dim target As Range ' target range in Invoice book
'clear target table
Sheet2.Cells.ClearContents

For mnth = 1 To 12
sfile = Format(DateSerial(Year(Date), mnth, 1), "MMMM")
sfilename = Dir(sfile & ".xls")
If sfilename < "" Then
Set wb = Workbooks.Open(sfilename)
Set source = wb.Worksheets("sheet1").Range("A1").CurrentRegion
With ThisWorkbook.Worksheets("sheet2")
If .Range("A1") = "" Then
Set target = .Range("A1")
Else
Set target = .Range("A1").End(xlDown).Offset(1)
End If
End With
With source
target.Resize(.Rows.Count, .Columns.Count).Value = .Value
target.Offset(, 2).Resize(.Rows.Count, 1) = sfile
End With

wb.Close False
Set wb = Nothing
End If
Next
End Sub

After running this sub, you'll have in sheet2 a table with three columns
A is the Invoice
B is the Amount
C is the Month

all you need to do now is an array formula in c,
eg C2
{==SUM((Sheet2!A2:A9=Sheet1!A2)*(Sheet2!C2:C9=Shee t1!B2)*(Sheet2!B2:B9)) }










"smartin" wrote in message
...
Gareth.Evans wrote:
HI all,

I am strugling to produce the bellow functionallity for a reporting
system.

I have a main workbook ('Invoice') which contains invoice numbers, i
needs to look up data in several other workbooks
('January','Febuary','March'), consolidate the data corrosponding to a
certain invoice, then import it into a sheet in the main workbook.

EXAMPLE:

Workbook 'Invoice', sheet 1:

Invoice Number | Lookup Workbook
2 January
3 Febuary
4 March
5 Febuary
6 January


Workbook 'Febuary', sheet 1:

Invoice Number | Amount
3 10
3 30
3 15
5 50
5 30

FINAL Desired Result in Workbook 'Invoice', sheet 2

Invoice Number | Amount
3 55
5 80

Hope that makes sense. This is obvoicesly a simple example, in real i
need to import many other fields for thousands of records.

Realy hope someone can help me.

Kind Regards,




Have a look at Debra Dalgleish's explanation of the technique he

http://www.contextures.com/xlFunctions05.html#RefWkbk


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro stops working when save as xlsm - any ideas? TomCon via OfficeKB.com Excel Programming 3 April 16th 09 12:30 PM
Slow Print out of the last of 3 pages in this macro any ideas????? Need Help pano[_3_] Excel Programming 0 October 23rd 07 10:15 PM
This Macro halts any ideas what could be wrong pano Excel Worksheet Functions 4 February 24th 07 06:26 AM
Macro speed decreased now to great extent Madiya Excel Programming 2 September 21st 06 10:21 AM
Have this great Macro, but!! Jim May Excel Programming 1 May 19th 06 06:07 PM


All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"