• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

What am I doing incorrect here: wb2 is not getting activated/onscreen/visibleworkbook

Mr.Karr

Member
Hello

I have an activity where I need to create a new workbook, copy data from it and paste back to actual workbook. Before moving back to source workbook, I need to allow user to make some changes with the newly created workbook ie wb2.

Below are the code I use;

Code:
  Dim ctl As Control
    Dim RowCount As Long
    Dim myPath As String
    Dim wb2 As Workbook

    Application.ScreenUpdating = False

Set wb2 = Workbooks.Add
wb2.Activate
With ActiveSheet.Range("A1")
ActiveCell.PasteSpecial
End With

Unload Me
   
Dim n As Integer, rng As Range
'n = InputBox("type the value of n")
Set rng = Range("A1:AN1")
rng.Select
line2:
n = InputBox("Total number of entries?")
Range(rng.Offset(1, 0), rng.Offset(n, 0)).EntireRow.Insert
Range(rng, rng.End(xlToRight)).Copy
Range(rng, rng.Offset(n, 0)).PasteSpecial
Set rng = rng.Offset(n + 1, 0)
Range("a1").Select
Columns("A:AN").EntireColumn.AutoFit

Application.ScreenUpdating = True


wb2.Activate

Please advise.

Many thanks in advance.
 
With the Unload Me command, it looks like you're running this from a user form? That command closes a user form completely, same as if you closed a workbook while a macro was running (it will stop mid stream). You should unload the from either as the last command (or hide it), and have it be unloaded by the macro that called the user form (showed it).
 
Back
Top