+ Reply to Thread
Results 1 to 2 of 2

Moving a worksheet via Userform

  1. #1
    Registered User
    Join Date
    02-03-2016
    Location
    Yorkshire
    MS-Off Ver
    Excel 2013
    Posts
    1

    Moving a worksheet via Userform

    Hi all

    I'm new to VBA programming and have been able to get most of my macro to work however there are a couple of things I can't get to work. My current code is:

    Sub FunctionsMenuNew()

    Application.ScreenUpdating = False
    Call SetGlobalVariables

    ActiveWorkbook.Sheets.Add After:=Worksheets("TEMPLATE")

    'Copy template
    ActiveWorkbook.Sheets("TEMPLATE").Copy After:=ActiveWorkbook.Sheets("Template")
    ActiveSheet.Name = "New KET"
    ThisWorkbook.VBProject.VBComponents("TEMPLATE1").Name = "NewKET"
    'Setting Cases/Units
    Worksheets("New KET").Range("D3").Value = frmFunctionsMenuNew.UOMListBox.Value
    'Copy and paste
    Dim i As Integer
    Dim intQty As Integer
    intQty = frmFunctionsMenuNew.ProductsListBox.Value
    For i = 1 To intQty
    Worksheets("New KET").Rows(1).Resize(38).Copy
    Worksheets("New KET").Rows(1).Offset(38 * i).PasteSpecial xlPasteAll
    Next i
    'moving sheet
    Dim j As Integer, Sht As String
    If KETListBox.Selected(i) = True Then
    Sht = KETListBox.List(i)
    Worksheets("New KET").Move After:=Sheets("frmFunctionsMenuNew.KETListBox.Value")
    'Rename worksheet name and VBA name
    ActiveSheet.Name = frmFunctionsMenuNew.KETNameTextBox.Value
    ThisWorkbook.VBProject.VBComponents("NewKET").Name = frmFunctionsMenuNew.KETCodeNameTextBox.Value
    'Put name and nbr in sDATA
    Dim intLastRow As Integer
    Worksheets("sDATA").Select
    'intLastRow = Sheets.Cells("BA").End(xlUp).Row
    intLastRow = Range("BA" & Rows.Count).End(xlUp).Row
    Worksheets("SData").Range("BA" & intLastRow).Value = frmFunctionsMenuNew.KETNameTextBox.Value
    Worksheets("SData").Range("BB" & intLastRow).Value = intQty


    Application.ScreenUpdating = True
    End Sub

    Everything works until i come to move the sheet. On my UserForm I have a list box with a list of the worksheets in the active workbook. What I'm after doing is getting the user to select where in the workbook the new sheet is to go. At the moment it is putting it in after a sheet called Template.

    It's also creating an additional blank sheet after creating a copy of TEMPLATE (New KET). Is there anyway to stop this.

    The final issue I haven't figured out is on a sheet called sDATA in columns BA & BB there is a list of the sheets which have been set up and the number of products per sheet. It needs to be in the same order as the sheets themselves. I've got my code to add the name of the sheet and the number of products onto the bottom of the list but I was wondering if there is a way to sort it to match the list of worksheets.

    If you could let me know where I'm going wrong on any of the above it would be really appreciated.

    Cheers

    Chris

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Moving a worksheet via Userform

    Please upload a sample workbook with your userform and code, it will make it a lot easier for people to help you out.
    Also, when posting code, please use code tags. To do this, highlight your code in the post then click the # symbol. You will have to click Edit post at the bottom right hand side of your post first.
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Moving data from a worksheet to a userform
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-21-2015, 02:23 PM
  2. Activation of Userform Hide Worksheet and Closing Userform Activates Worksheet
    By Newmord in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2014, 11:18 AM
  3. [SOLVED] Moving Date from UserForm to UserForm
    By wlugo13 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-17-2013, 05:17 PM
  4. moving data from a userform listbox to a worksheet
    By Khaos176 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-09-2009, 12:43 PM
  5. Userform moving text
    By pauluk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2007, 05:59 PM
  6. moving on userform
    By Zygan in forum Excel General
    Replies: 1
    Last Post: 07-27-2006, 04:00 AM
  7. [SOLVED] moving an image in a userform
    By Gixxer_J_97 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-18-2005, 08:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1