+ Reply to Thread
Results 1 to 3 of 3

Easy VB code question

  1. #1
    Anthony
    Guest

    Easy VB code question

    Hi,
    I'm the novice so I'm sure this will be easy for you guys.
    Ok I have a macro to create a new worksheet for a new order placed. The
    worksheet is named from the input data from cell B2.
    The code will copy some data into the new worksheet and then use a message
    box to acknowledge that the order has been placed.
    What I can't get to work is that I want this msg box to be shown back in
    the original 'order form' worksheet and not the newly created one.
    ie I want all the selected data from the order to be pasted into the new
    worksheet - and the only notice that this has been done will be the msg box !
    hope I have made that clear, and here is my code

    Sub NewSheet()
    Dim x As Worksheet
    Dim y As Worksheet
    Dim z As Variant

    Set x = ActiveSheet
    With Sheets.Add
    ActiveSheet.Name = x.Range("B2")
    Set y = ActiveSheet

    z = Array(x.Range("B2"), x.Range("B4")

    y.Range("B3") = z(0) 'NAME
    y.Range("D3") = z(1) 'BOOKING REF

    End With
    MsgBox "Thank You, Order Created Successfully !", vbInformation


    End Sub

    many thanks




  2. #2
    Chad
    Guest

    RE: Easy VB code question

    before your msgbox write Sheets("Sheet 1").select and replace the Sheet 1
    text with whatever the sheet name that you want to select.

    "Anthony" wrote:

    > Hi,
    > I'm the novice so I'm sure this will be easy for you guys.
    > Ok I have a macro to create a new worksheet for a new order placed. The
    > worksheet is named from the input data from cell B2.
    > The code will copy some data into the new worksheet and then use a message
    > box to acknowledge that the order has been placed.
    > What I can't get to work is that I want this msg box to be shown back in
    > the original 'order form' worksheet and not the newly created one.
    > ie I want all the selected data from the order to be pasted into the new
    > worksheet - and the only notice that this has been done will be the msg box !
    > hope I have made that clear, and here is my code
    >
    > Sub NewSheet()
    > Dim x As Worksheet
    > Dim y As Worksheet
    > Dim z As Variant
    >
    > Set x = ActiveSheet
    > With Sheets.Add
    > ActiveSheet.Name = x.Range("B2")
    > Set y = ActiveSheet
    >
    > z = Array(x.Range("B2"), x.Range("B4")
    >
    > y.Range("B3") = z(0) 'NAME
    > y.Range("D3") = z(1) 'BOOKING REF
    >
    > End With
    > MsgBox "Thank You, Order Created Successfully !", vbInformation
    >
    >
    > End Sub
    >
    > many thanks
    >
    >
    >


  3. #3
    Anthony
    Guest

    RE: Easy VB code question

    Brill, thanks Chad

    "Chad" wrote:

    > before your msgbox write Sheets("Sheet 1").select and replace the Sheet 1
    > text with whatever the sheet name that you want to select.
    >
    > "Anthony" wrote:
    >
    > > Hi,
    > > I'm the novice so I'm sure this will be easy for you guys.
    > > Ok I have a macro to create a new worksheet for a new order placed. The
    > > worksheet is named from the input data from cell B2.
    > > The code will copy some data into the new worksheet and then use a message
    > > box to acknowledge that the order has been placed.
    > > What I can't get to work is that I want this msg box to be shown back in
    > > the original 'order form' worksheet and not the newly created one.
    > > ie I want all the selected data from the order to be pasted into the new
    > > worksheet - and the only notice that this has been done will be the msg box !
    > > hope I have made that clear, and here is my code
    > >
    > > Sub NewSheet()
    > > Dim x As Worksheet
    > > Dim y As Worksheet
    > > Dim z As Variant
    > >
    > > Set x = ActiveSheet
    > > With Sheets.Add
    > > ActiveSheet.Name = x.Range("B2")
    > > Set y = ActiveSheet
    > >
    > > z = Array(x.Range("B2"), x.Range("B4")
    > >
    > > y.Range("B3") = z(0) 'NAME
    > > y.Range("D3") = z(1) 'BOOKING REF
    > >
    > > End With
    > > MsgBox "Thank You, Order Created Successfully !", vbInformation
    > >
    > >
    > > End Sub
    > >
    > > many thanks
    > >
    > >
    > >


+ Reply to Thread

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