Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


error in code

error in code

error in code

Who can help me solving the error in the code below...


Sub Start_Excel_Proces()

'Declare file dialog, Excel workbook and application objects
Dim fd As FileDialog
Dim newsheet As Boolean
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

'Declare the used vars and constants
Dim i As Integer
Dim LR As Integer
Dim LC As Integer

' select excel-file
Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.Title = "Selecting Excel Result File"
    fd.InitialFileName = ExcelResultDir
    fd.InitialView = msoFileDialogViewList
    fd.Filters.Add "Excel-files", "*.xls*"
    fd.FilterIndex = 1
    fd.ButtonName = "Choose &This file"
    If fd.Show <> -1 Then
        MsgBox "Macro stopped without selecting a Excel Result File"
        GoTo labelend
    End If

Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Open(fd.SelectedItems(1))

newsheet = True
For Each xlWS In xlWB.Worksheets
    If xlWS.Name = Customer Then
        newsheet = False
        Exit For
    End If

If newsheet Then
    xlWB.Sheets("template").Visible = xlSheetVisible
    xlWB.Sheets("template").Copy After:=xlWB.Sheets(Sheets.count)
    xlWB.Sheets("template").Visible = xlSheetVeryHidden
    xlWB.Sheets(Sheets.count).Name = Customer
End If

LR = lastrow(xlWB.Sheets(Customer), 1)
xlWB.Sheets(Customer).Cells(LR + 1, 1).Value = LIMSinfoArray(1)
xlWB.Sheets(Customer).Cells(LR + 1, 2).Value = OrderdataArray(1)
xlWB.Sheets(Customer).Cells(LR + 1, 3).Value = OrderdataArray(3)
xlWB.Sheets(Customer).Cells(LR + 1, 4).Value = OrderdataArray(2)
xlWB.Sheets(Customer).Cells(LR + 1, 5).Value = NCdata(1)
xlWB.Sheets(Customer).Cells(LR + 1, 6).Value = NCdata(2)

Set xlApp = Nothing
Set xlWB = Nothing
Set xlWS = Nothing
End Sub 

I get an error in the command


xlWB.Sheets("template").Copy After:=xlWB.Sheets(Sheets.count) 

Run time error : '1004'
Method 'Range' of 'object' Global Failed

RE: error in code

xlWB.Sheets("template").Copy After:=xlWB.Sheets(xlWb.Sheets.count)


RE: error in code

Very good Combo !!!
It works perfectly.

Thank you very much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close