Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Filling in data into adjacent column utilizing VBA

I have multiple workbooks that I retrieve data from, the workbook count can
change month to month. I bring this data into a separate workbook to produce
the report.
Lets say the multiple workbooks are 1,2,3,4 and my report is "Summary". In
all workbooks column A contains the store # (which could be interpreted as
the primary key)

In column B of Summary it will look for the matching store #'s in column B
of workbook 1 and retrieve the data in column C then place that data in
column C of the Summary. Once the all the data has been retrieved I want it
to move to column C of the summary and start looking for data from workbook 2
repeating the process etc...

The problem I have is, once I have all the data from workbook 1, how do I
move to workbook 2. Getting the data out and into the summary is not the
issue, just going to the next workbook

Thanks for the help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Filling in data into adjacent column utilizing VBA

Maybe some approach like this:

Dim bksum as workbook, rngSum as Range
Dim bk1 as workbook, rng1 as Range
Dim bk2 as Workbook, rng2 as Range
Dim cell as Range, rng as Range
Dim res as Variant
set bkSum = Workbooks("Summary.xls")
set bk1 = Workbooks("Book1.xls")
set bk2 = Workbooks("book2.xls")

with bkSum.worksheets(1)
set rngSum = .range(.Cells(2,2),.Cells(2,2).End(xldown))
End with

with bk1.Worksheets(1)
set rng1 = .Range(.Cells(2,2),.Cells(2,2).End(xldown))
End with

with bk2.Worksheets(1)
set rng2 = .Range(.Cells(2,2),.Cells(2,2).end(xldown))
End with

for each cell in rngSum
res = Application.Match(cell,rng1,0)
if not iserror(res) then
set rng = rng1(res)
cell.offset(0,1).Value = rng.offset(0,1)
end if
Next

for each cell in rng.Sum.Offset(0,1)
if cell < "" then
res = Application.Match(cell,rng2,0)
if not iserror(res) then
set rng = rng2(res)
cell.offset(0,1).Value = rng.offset(0,1).Value
end if
end if
Next

--
Regards,
Tom Ogilvy

"Hans" wrote:

I have multiple workbooks that I retrieve data from, the workbook count can
change month to month. I bring this data into a separate workbook to produce
the report.
Lets say the multiple workbooks are 1,2,3,4 and my report is "Summary". In
all workbooks column A contains the store # (which could be interpreted as
the primary key)

In column B of Summary it will look for the matching store #'s in column B
of workbook 1 and retrieve the data in column C then place that data in
column C of the Summary. Once the all the data has been retrieved I want it
to move to column C of the summary and start looking for data from workbook 2
repeating the process etc...

The problem I have is, once I have all the data from workbook 1, how do I
move to workbook 2. Getting the data out and into the summary is not the
issue, just going to the next workbook

Thanks for the help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Filling in data into adjacent column utilizing VBA

Tom,

Thanks for the response, I will play with it and let you know what I come up
with.

Hans

"Tom Ogilvy" wrote:

Maybe some approach like this:

Dim bksum as workbook, rngSum as Range
Dim bk1 as workbook, rng1 as Range
Dim bk2 as Workbook, rng2 as Range
Dim cell as Range, rng as Range
Dim res as Variant
set bkSum = Workbooks("Summary.xls")
set bk1 = Workbooks("Book1.xls")
set bk2 = Workbooks("book2.xls")

with bkSum.worksheets(1)
set rngSum = .range(.Cells(2,2),.Cells(2,2).End(xldown))
End with

with bk1.Worksheets(1)
set rng1 = .Range(.Cells(2,2),.Cells(2,2).End(xldown))
End with

with bk2.Worksheets(1)
set rng2 = .Range(.Cells(2,2),.Cells(2,2).end(xldown))
End with

for each cell in rngSum
res = Application.Match(cell,rng1,0)
if not iserror(res) then
set rng = rng1(res)
cell.offset(0,1).Value = rng.offset(0,1)
end if
Next

for each cell in rng.Sum.Offset(0,1)
if cell < "" then
res = Application.Match(cell,rng2,0)
if not iserror(res) then
set rng = rng2(res)
cell.offset(0,1).Value = rng.offset(0,1).Value
end if
end if
Next

--
Regards,
Tom Ogilvy

"Hans" wrote:

I have multiple workbooks that I retrieve data from, the workbook count can
change month to month. I bring this data into a separate workbook to produce
the report.
Lets say the multiple workbooks are 1,2,3,4 and my report is "Summary". In
all workbooks column A contains the store # (which could be interpreted as
the primary key)

In column B of Summary it will look for the matching store #'s in column B
of workbook 1 and retrieve the data in column C then place that data in
column C of the Summary. Once the all the data has been retrieved I want it
to move to column C of the summary and start looking for data from workbook 2
repeating the process etc...

The problem I have is, once I have all the data from workbook 1, how do I
move to workbook 2. Getting the data out and into the summary is not the
issue, just going to the next workbook

Thanks for the help!

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
Filling adjacent formulas with data import Dave Excel Discussion (Misc queries) 1 May 17th 10 08:44 AM
FInd common data in one column then add number in adjacent column JT Excel Worksheet Functions 3 December 18th 09 10:20 PM
When data match, copy adjacent value to adjacent column slimbim Excel Worksheet Functions 2 November 8th 06 08:41 PM
summing values from adjacent column with refrence from adjacent column Pivotrend Excel Discussion (Misc queries) 6 March 4th 06 11:24 AM
How to copy data validation utilizing a list to the entire column Sonjab Excel Worksheet Functions 0 September 8th 05 02:28 PM


All times are GMT +1. The time now is 12:43 AM.

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

About Us

"It's about Microsoft Excel"