Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Skipping sheets when copying

I have a code, that copies sheets from one workbook to another. The code looks like this:

Sub CopyShees()
Path = Range("h1")
Filename = Dir(Path & "*.xlsm")
Do While Filename < ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(worksheets.count)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub

And it actually works. But I like it to skip the sheets in the Activeworkbook, that already exist in ThisWorkbook, so it only copies "new" sheets from the active workbook.

I have treid different approaches but with no succes so far. Anybody?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Skipping sheets when copying

Hi Jan,

Am Thu, 10 Sep 2020 14:22:53 -0700 (PDT) schrieb Jan Kronsell:

I have a code, that copies sheets from one workbook to another. The code looks like this:


[code snipped]

And it actually works. But I like it to skip the sheets in the Activeworkbook, that already exist in ThisWorkbook, so it only copies "new" sheets from the active workbook.


try:

Option Explicit
Public wbk As String

Sub CopySheets()
Dim myPath As String
Dim FN As String
Dim wsh As Worksheet
Dim shCount As Integer

wbk = ThisWorkbook.Name
'Modify the sheet name
myPath = ThisWorkbook.Sheets("Sheet1").Range("H1")
FN = Dir(myPath & "*.xlsm")
Do While FN < ""
shCount = ThisWorkbook.Sheets.Count
Workbooks.Open (myPath & FN)
For Each wsh In ActiveWorkbook.Worksheets
If SheetExists(wsh.Name) = False Then
wsh.Copy After:=ThisWorkbook.Sheets(shCount)
End If
Next wsh
Workbooks(FN).Close
FN = Dir()
Loop
End Sub

Function SheetExists(strShName As String) As Boolean
On Error Resume Next
SheetExists = Not Workbooks(wbk).Sheets(strShName) Is Nothing
End Function


Regards
Claus B.
--
Windows10
Office 2016
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Skipping sheets when copying

Hi Claus

Sorry for my late reply, but I have been on a business trip. Your solution works soothly. Thank you.

Regards
Jan
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 a formula but not skipping ref cells Picc About this forum 0 March 8th 13 01:05 AM
Copying a formula but 'skipping' a cell Mike Langensiepen New Users to Excel 2 May 3rd 07 06:17 AM
Copying values skipping blanks justaguyfromky Excel Programming 1 February 9th 07 12:27 AM
Copying and skipping (adding) rows [email protected] Excel Programming 1 January 22nd 06 06:35 PM
copying and skipping consecutive row data archie Excel Programming 0 November 15th 04 10:05 PM


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