Results 1 to 2 of 2

Quick Question about switching sheets through VBA code

Threaded View

richter394 Quick Question about... 05-02-2013, 10:25 AM
jaslake Re: Quick Question about... 05-02-2013, 02:27 PM
  1. #1
    Registered User
    Join Date
    02-10-2013
    Location
    Really
    MS-Off Ver
    Excel 2007
    Posts
    25

    Quick Question about switching sheets through VBA code

    Book1.xlsm

    Attached is an example of what I need:

    So I have a userform that is opened from the first sheet. When it is opened, the workbook switches to sheet 2.

    I have the VBA for adding and deleting the data I want. I just need a real simple VBA code for pasting the values into sheet 1 instead of the active sheet which is sheet 2. Below is the vba code for what I have.

    Private Sub CommandButton1_Click()
    With ThisWorkbook.ActiveSheet
    .Range("C4").Value = Me.TextBox1.Value
    .Range("C5").Value = Me.TextBox2.Value
    'Clear old data
    .Range("A2", .Range("A" & Rows.Count).End(xlUp)).ClearContents

    With .Range("A2").Resize(Me.TextBox1.Value)
    .Formula = "=NORMINV(RAND(),$C$5,$H$7)"
    .Value = .Value 'Convert formulas to values
    End With
    End With
    Unload Me

    End Sub


    Essentially my values are pasted into sheet 2, but I want the random numbers to be generated in sheet 1 column A. How do i do this?
    Last edited by richter394; 05-02-2013 at 10:45 AM. Reason: Better Description and Attachment

Thread Information

Users Browsing this Thread

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

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