Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default More used range Q's


I am trying to copy the used range from a specified selection o
worksheets, this time within
one workbook. I only want to take the header row from one sheet and no
from the rest. I have used the helpful tip outlined below (only segmen
of code) but it copies all worksheets within the workbook with al
headers included.


Sub CopyUsedRange()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
If SheetExists("Master") = True Then
MsgBox "The sheet Master already exist"
Exit Sub
End If
Application.ScreenUpdating = False
Set DestSh = Worksheets.Add
DestSh.Name = "Master"
For Each sh In ThisWorkbook.Worksheets
If sh.Name < DestSh.Name Then
If sh.UsedRange.Count 1 Then
Last = LastRow(DestSh)
sh.UsedRange.Copy DestSh.Cells(Last + 1, 1)
End If
End If
Next
Application.ScreenUpdating = True
End Sub

Similar to my other post but I have outlined more and refined m
direction.
Thanks in advance.

Krista

--
Kstalke
-----------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...fo&userid=2469
View this thread: http://www.excelforum.com/showthread.php?threadid=38297

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default More used range Q's

Hi Kristan,

See Ron De Bruin's web site for a whole range of copy Cell(s) \ Range \
Sheet \ Workbook routines copy at:

http://www.rondebruin.nl/tips.htm


---
Regards,
Norman



"Kstalker" wrote in
message ...

I am trying to copy the used range from a specified selection of
worksheets, this time within
one workbook. I only want to take the header row from one sheet and not
from the rest. I have used the helpful tip outlined below (only segment
of code) but it copies all worksheets within the workbook with all
headers included.


Sub CopyUsedRange()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
If SheetExists("Master") = True Then
MsgBox "The sheet Master already exist"
Exit Sub
End If
Application.ScreenUpdating = False
Set DestSh = Worksheets.Add
DestSh.Name = "Master"
For Each sh In ThisWorkbook.Worksheets
If sh.Name < DestSh.Name Then
If sh.UsedRange.Count 1 Then
Last = LastRow(DestSh)
sh.UsedRange.Copy DestSh.Cells(Last + 1, 1)
End If
End If
Next
Application.ScreenUpdating = True
End Sub

Similar to my other post but I have outlined more and refined my
direction.
Thanks in advance.

Kristan


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile:
http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=382970



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default More used range Q's

Hi Kristan,

Looking again, I see that the code you show *is* Ron de Bruin's.

Try this adaptation of Ron's code (on a copy of your workbook!) and see if
it satisfies your requirements.

I have included the Ron's LastRow function and the Chip Pearson SheetExists
function for completenes and as these are required by the sub.

Sub CopyUsedRange()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Dim RngToCopy As Range
Dim Arr As Variant
Dim WB As Workbook
Dim i As Long

Set WB = ActiveWorkbook '<<===== CHANGE or KEEP

Arr = Array("Sheet1", "Sheet2", "Sheet3") '<<==== CHANGE

If SheetExists("Master", WB) = True Then
MsgBox "The sheet Master already exist"
Exit Sub
End If

Application.ScreenUpdating = False
Set DestSh = WB.Worksheets.Add
DestSh.Name = "Master"

For i = LBound(Arr) To UBound(Arr)
Set sh = Sheets(Arr(i))

With sh.UsedRange

If i = 1 Then .Rows(1).Copy DestSh.Cells(1)

Set RngToCopy = .Offset(1).Resize(.Rows.Count - 1)
If i = 1 Then .Rows(1).Copy DestSh.Cells(1)

End With

If sh.UsedRange.Count 1 Then
Last = LastRow(DestSh)
RngToCopy.Copy DestSh.Cells(Last + 1, 1)
End If

Next

Application.ScreenUpdating = True

End Sub
'<<=================

'=================
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


Function SheetExists(SName As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(SName).Name))
End Function

'<<=================
---
Regards,
Norman



"Kstalker" wrote in
message ...

I am trying to copy the used range from a specified selection of
worksheets, this time within
one workbook. I only want to take the header row from one sheet and not
from the rest. I have used the helpful tip outlined below (only segment
of code) but it copies all worksheets within the workbook with all
headers included.


Sub CopyUsedRange()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
If SheetExists("Master") = True Then
MsgBox "The sheet Master already exist"
Exit Sub
End If
Application.ScreenUpdating = False
Set DestSh = Worksheets.Add
DestSh.Name = "Master"
For Each sh In ThisWorkbook.Worksheets
If sh.Name < DestSh.Name Then
If sh.UsedRange.Count 1 Then
Last = LastRow(DestSh)
sh.UsedRange.Copy DestSh.Cells(Last + 1, 1)
End If
End If
Next
Application.ScreenUpdating = True
End Sub

Similar to my other post but I have outlined more and refined my
direction.
Thanks in advance.

Kristan


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile:
http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=382970



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default More used range Q's


Didn't intend on sounding like a plagarist, Ron de Bruin's code worked a
treat.

That adaptation is on the money, with one exception. Still misses the
first row on the first sheet. (not header) Otherwise pulls everything
together perfectly. Any idea how to include that initial row?

Thanks again
Kristan


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=382970

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default More used range Q's

Hi Kristan,

In the line:

If i = 1 Then .Rows(1).Copy DestSh.Cells(1)

try changing i=1 to i=2.


Didn't intend on sounding like a plagarist, Ron de Bruin's code worked a
treat.


And no such intention on my part to suggest this. In any event, I am sure
that Ron is only too happy for his published code to be used.

The comment to which you have responded was a metaphoric wry smile at
myself: I advised you to look at Ron's code offerings and you already had!

---
Regards,
Norman



"Kstalker" wrote in
message ...

Didn't intend on sounding like a plagarist, Ron de Bruin's code worked a
treat.

That adaptation is on the money, with one exception. Still misses the
first row on the first sheet. (not header) Otherwise pulls everything
together perfectly. Any idea how to include that initial row?

Thanks again
Kristan


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile:
http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=382970





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default More used range Q's

Hi Kristan,

Typo warning!

try changing i=1 to i=2.


should read:

try changing i=1 to i=0


..
---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Kristan,

In the line:

If i = 1 Then .Rows(1).Copy DestSh.Cells(1)

try changing i=1 to i=2.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default More used range Q's


All good.

Thanks for your knowledge and tenacity Norman.

Regards

Krista

--
Kstalke
-----------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...fo&userid=2469
View this thread: http://www.excelforum.com/showthread.php?threadid=38297

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
How do I enter formula sum(range+range)*0.15 sumif(range=3) tkw Excel Discussion (Misc queries) 2 October 1st 09 09:17 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 07:05 PM.

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"