Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default dynamic sheet copy

I wondered if anyone could help me modify this line of code,
so instead of it copying the sheet with index 1 it would be dynamic, so that
the user could input a string and this is the sheet that would be copied.

mybook.Worksheets(1).Copy after:= _
bsebk.Sheets(bsebk.Sheets.Count)

The routine is based around Ron de Bruin's sheet copy macro, I am just
trying to get to grips with generalising it.

Thanks in advance
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default dynamic sheet copy

Sub TryThis()
Dim mySheetName
Dim Sht As Worksheet
Dim SheetExist As Boolean
mySheetName = Application.InputBox(prompt:=Chr(10) & "Insert th
sheet NAME!", Type:=2)
If mySheetName = False Then Exit Sub
For Each Sht In ThisWorkbook.Sheets
If LCase(Sht.Name) = LCase(mySheetName) Then
SheetExist = True
Exit For
End If
Next Sht
If SheetExist = True Then
Sheets(mySheetName).Cop
after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
Else
MsgBox "The sheet name you inserted does not exist"
vbInformation + vbOKOnly, "I'm so Sorry, but:"
End If
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default dynamic sheet copy

I cant seem to get in in without an error occuring in the final lines,
can you help, maybe i'm putting the breaks in the wrong place, if this works I
can add it to the rest (From Ron) which loops around, that would be
brilliant!!!

I have to say I was surprised by how quickly someone got back to me

Thanks again for looking at this


"Andoni " wrote:

If SheetExist = True Then
Sheets(mySheetName).Copy
after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Cou nt)
Else
MsgBox "The sheet name you inserted does not exist",
vbInformation + vbOKOnly, "I'm so Sorry, but:"
End If




---
Message posted from http://www.ExcelForum.com/


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default dynamic sheet copy


I got it to work, however, my version XL97 doesnt seem to like
the End If statement. I'll play with this over the weekend to see if I
can put all of the code together.

Thanks again

John


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default dynamic sheet copy

If you have an IF then you need an end if IF more than one line

if tt then
ddd
end if

or
if tt then ddd

no end if needed

--
Don Guillett
SalesAid Software

"John" wrote in message
...

I got it to work, however, my version XL97 doesnt seem to like
the End If statement. I'll play with this over the weekend to see if I
can put all of the code together.

Thanks again

John



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
Copy worksheet with dynamic chart? [email protected][_2_] Charts and Charting in Excel 1 March 27th 09 12:07 PM
Dynamic column chart - copying from Sheet to Sheet. Marko Pinteric Excel Discussion (Misc queries) 1 April 10th 06 12:57 PM
Dynamic column chart - copying from Sheet to Sheet. Marko Pinteric Charts and Charting in Excel 1 April 10th 06 12:57 PM
Reference / Copy Dynamic Data mupps Excel Discussion (Misc queries) 1 October 31st 05 03:03 PM
How to Copy worksheet to new workbook with dynamic name? Ashleigh K. Excel Programming 1 December 30th 03 09:10 PM


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