Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Merging Worksheets in Excel

I can merge the worksheets with no problem, but on the worksheet I'm
updating from the others, there's a column at the end that gets
overwritten every time and I want it to remain static. Any ideas?
Here's the code I'm using for the merge which was gratefully clipped
from http://www.rondebruin.nl/copy2.htm

Private Sub CommandButton1_Click()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Application.ScreenUpdating = False
Set DestSh = Worksheets("Merged")
Worksheets("Merged").UsedRange.Offset(4,0).ClearCo ntents
For Each sh In Sheets(Array("Sheet2", "Sheet3"))
LastR = LastRow(DestSh)
sh.UsedRange.Offset(4, 0).Copy DestSh.Cells(LastR + 1, 1)
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:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Function LastCol(sh As Worksheet)
On Error Resume Next
LastCol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Merging Worksheets in Excel

is the column in the sheet before any copying? If so, you woulr clear it
with

Worksheets("Merged").UsedRange.Offset(4,0).ClearCo ntents


You would need to use

set rng = worksheets("Merged").UsedRange.Offset(4,0)
Intersect(rng,worksheets("Merged").Columns(1).Resi ze(10)).Clearcontents

Change the 10 to reflect the number of columns you want cleared starting
from column A.

--
Regards,
Tom Ogilvy

"TommyJ" wrote in message
...
I can merge the worksheets with no problem, but on the worksheet I'm
updating from the others, there's a column at the end that gets
overwritten every time and I want it to remain static. Any ideas?
Here's the code I'm using for the merge which was gratefully clipped
from http://www.rondebruin.nl/copy2.htm

Private Sub CommandButton1_Click()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim Last As Long
Application.ScreenUpdating = False
Set DestSh = Worksheets("Merged")
Worksheets("Merged").UsedRange.Offset(4,0).ClearCo ntents
For Each sh In Sheets(Array("Sheet2", "Sheet3"))
LastR = LastRow(DestSh)
sh.UsedRange.Offset(4, 0).Copy DestSh.Cells(LastR + 1, 1)
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:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function

Function LastCol(sh As Worksheet)
On Error Resume Next
LastCol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/



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
Excel merging and automatic edit of worksheets Moonie66 Excel Worksheet Functions 0 March 17th 10 08:36 PM
merging worksheets KRK New Users to Excel 1 June 25th 09 03:30 PM
Merging Excel Worksheets jeanmarie711 Excel Discussion (Misc queries) 9 September 12th 08 04:28 PM
Merging worksheets into one Edward Owen Excel Worksheet Functions 2 May 17th 06 06:50 PM
Need help merging worksheets carmeljo Excel Discussion (Misc queries) 4 January 28th 06 11:15 PM


All times are GMT +1. The time now is 06:56 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"