Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying spreadsheets in directory into master spreadsheet


Hello everyone,
I am trying to make some VBA code which will copy all the spreadsheets
within a specified directory into one master spreadsheet. I am new at
this, and have cannibalized some code from this site to do this. The
problem I am having is with changing the row heights and column widths
to match the spreadsheets I am getting the data from. I have two
formulas, CopyColumnWidths and CopyRowHeigths, set up like so:

Private Sub CopyRowHeigths(TargetRange As Range, SourceRange As Range)

I am trying to pass in the range of all the used cells from the first
spreadsheet in the directory I am getting data from as the first
parameter. To get the second parameter, I have a formula that finds
the last row with data in it. I use this formula on the master sheet
before copying data from the first sheet in the directory and as
StartRow as the result. Then I copy the data. Then I use this formula
again and cas EndRow as the result. Now I am trying to set up a range
that I can pas into CopyRowHeigths and CopyRowWidths. I am not sure
how to do this. One idea I had was to make a string and then convert
it into a range. Here is what I have:

DestRangeStr = "DestSh.Range(\""" + StartRow + "1:" + EndRow + "1" +
"\""" + ")"
DestRange = DestRangeStr
CopyColumnWidths(sh.UsedRange, DestRange)
CopyRowHeigths(sh.UsedRange, DestRange)

I am not sure if I am using the code correctly to put the quotation
mark into the string. I thought if I used the escape key, \, and then
a quotation mark it would put that within the string. The compiler
automatically put a third quotation mark in for me so it looked like
this: \""". I'm not sure if this is right. Does anyone know what I'm
doing wrong or have a better way to do it?


--
dtguitarfan
------------------------------------------------------------------------
dtguitarfan's Profile: http://www.excelforum.com/member.php...o&userid=24403
View this thread: http://www.excelforum.com/showthread...hreadid=380065

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Copying spreadsheets in directory into master spreadsheet

If you copy the complete row, then the rowheight will change when you paste it.

dim DestRng as range
dim SourceRng as range

with SomeWorkbook.worksheets("sheet1")
set sourcerng = .range("a1",.cells(.rows.count,"A").end(xlup))
end with

with otherworkbook.worksheets("sheet1")
set destrng = 'whatever you used to get the next row
end with

sourcerng.entirerow.copy _
destination:=destrng


====
But I think you've got a problem with the columnwidths. If you're pasting
several worksheets into one giant worksheet, then what columnwidth would you use
for the monster worksheet? Each of the several could have different
columnwidths.


dtguitarfan wrote:

Hello everyone,
I am trying to make some VBA code which will copy all the spreadsheets
within a specified directory into one master spreadsheet. I am new at
this, and have cannibalized some code from this site to do this. The
problem I am having is with changing the row heights and column widths
to match the spreadsheets I am getting the data from. I have two
formulas, CopyColumnWidths and CopyRowHeigths, set up like so:

Private Sub CopyRowHeigths(TargetRange As Range, SourceRange As Range)

I am trying to pass in the range of all the used cells from the first
spreadsheet in the directory I am getting data from as the first
parameter. To get the second parameter, I have a formula that finds
the last row with data in it. I use this formula on the master sheet
before copying data from the first sheet in the directory and as
StartRow as the result. Then I copy the data. Then I use this formula
again and cas EndRow as the result. Now I am trying to set up a range
that I can pas into CopyRowHeigths and CopyRowWidths. I am not sure
how to do this. One idea I had was to make a string and then convert
it into a range. Here is what I have:

DestRangeStr = "DestSh.Range(\""" + StartRow + "1:" + EndRow + "1" +
"\""" + ")"
DestRange = DestRangeStr
CopyColumnWidths(sh.UsedRange, DestRange)
CopyRowHeigths(sh.UsedRange, DestRange)

I am not sure if I am using the code correctly to put the quotation
mark into the string. I thought if I used the escape key, \, and then
a quotation mark it would put that within the string. The compiler
automatically put a third quotation mark in for me so it looked like
this: \""". I'm not sure if this is right. Does anyone know what I'm
doing wrong or have a better way to do it?

--
dtguitarfan
------------------------------------------------------------------------
dtguitarfan's Profile: http://www.excelforum.com/member.php...o&userid=24403
View this thread: http://www.excelforum.com/showthread...hreadid=380065


--

Dave Peterson
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
copying data from master ti individual sheets minimoi Excel Discussion (Misc queries) 3 January 19th 10 09:45 PM
How Do I Automatically Link New Spreadsheets to One Master File? gabonais Excel Discussion (Misc queries) 3 December 27th 07 09:51 PM
Automatically Linking New Spreadsheets to Master File gabonais Excel Worksheet Functions 1 December 24th 07 08:20 PM
Combining spreadsheets to a master sheet [email protected] Excel Discussion (Misc queries) 1 May 18th 07 11:28 PM
Copying From Master teresa Excel Programming 1 May 29th 05 05:53 PM


All times are GMT +1. The time now is 12:57 PM.

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"