+ Reply to Thread
Results 1 to 11 of 11

run time error 1004 - method range of object worksheet failed.

  1. #1
    Registered User
    Join Date
    02-11-2016
    Location
    dubai
    MS-Off Ver
    msoffice 2010
    Posts
    75

    run time error 1004 - method range of object worksheet failed.

    Dear Friends,

    Below is the VBA codes where i tried in my excel. I am new to this. Need help from your team.
    Please look at the mcopy, where i am trying to copy the cells which is listed below..
    but upto q11 my vba code is working. after that even one cell not accepting
    I need to write many cells like this
    PLEASE support.





    Sub MISOTTINPUT()
    '

    ' MISOTTINPUT Macro
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim nextRow As Long
    Dim oCol As Long

    Dim myRng As Range
    Dim myCopy As String
    Dim myCell As Range


    'cells to copy from Input sheet - some contain formulas
    myCopy = "b6,C6,d6,e6,f6,g6,h6,i6,j6,k6,l6,m6,n6,o6,p6,q6,R6,S6,b7,C7,d7,e7,f7,g7,h7,i7,j7,k7,l7,m7,n7,o7,p7,q7,R7,S7,b8,C8,d8,e8,f8,g8,h8,i8,j8,k8,l8,m8,n8,o8,p8,q8,r8,s8,m10,n10,o10,p10,q10,R10,S10,b11,C11,d11,e11,f11,g11,h11,i11,j11,k11,l11,m11,n11,o11,p11,q11,r11"


    Set inputWks = Worksheets("Sheet2")
    Set historyWks = Worksheets("MISOUTWARD")

    With historyWks
    nextRow = .Cells(.Rows.Count, "E").End(xlUp).Offset(1, 0).Row
    End With


    With inputWks
    Set myRng = .Range(myCopy)


    If Application.CountA(myRng) <> myRng.Cells.Count Then
    MsgBox "Hey you must write all the cells!"
    Exit Sub
    End If
    End With



    With historyWks
    With .Cells(nextRow, "C")
    .Value = Now
    .NumberFormat = "mm/dd/yyyy hh:mm:ss"
    End With
    .Cells(nextRow, "kk").Value = Application.UserName
    oCol = 4
    For Each myCell In myRng.Cells
    historyWks.Cells(nextRow, oCol).Value = myCell.Value
    oCol = oCol + 1
    Next myCell
    End With



    ' Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
    'Working in Excel 2002-2013
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range

    On Error GoTo StopMacro

    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    End With

    'Fill in the Worksheet/range you want to mail
    'Note: if you use one cell it will send the whole worksheet
    Set Sendrng = Worksheets("Sheet2").Range("A1:I27")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet

    With Sendrng

    ' Select the worksheet with the range you want to send
    .Parent.Select

    'Remember the ActiveCell on that worksheet
    Set rng = ActiveCell

    'Select the range you want to mail
    .Select

    ' Create the mail and send it
    ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope

    ' Set the optional introduction field thats adds
    ' some header text to the email body.
    .Introduction = "These are the MIS recorded for the Outward Team"

    With .Item

    .To = "anuwers@gmail.com"

    .Subject = "Daily MIS of Number of TT's Processed and the Internal Errors"
    .Send
    End With

    End With

    'select the original ActiveCell
    rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

    StopMacro:
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

    'clear input cells that contain constants
    With inputWks
    On Error Resume Next
    With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
    .ClearContents
    Application.GoTo .Cells(1) ', Scroll:=True
    End With
    On Error GoTo 0
    End With

    'clear input cells that contain constants
    With inputWks
    On Error Resume Next
    With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
    .ClearContents
    Application.GoTo .Cells(1) ', Scroll:=True
    End With
    On Error GoTo 0
    End With

    Sheets("Sheet2").Select
    Range("C4").Select
    Range(Selection, Selection.End(xlDown)).Select


    End Sub
    Last edited by anuwers; 02-11-2016 at 06:31 PM.

  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: run time error 1004 - method range of object worksheet failed.

    Deleted...posted twice
    Last edited by gmr4evr1; 02-11-2016 at 07:32 PM.
    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

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

    Re: run time error 1004 - method range of object worksheet failed.

    I've made some slight changes to your code, see if it works for you..
    Please Login or Register  to view this content.
    I wasn't sure where your mycopy range was so I just did it on sheet1

  4. #4
    Registered User
    Join Date
    02-11-2016
    Location
    dubai
    MS-Off Ver
    msoffice 2010
    Posts
    75

    Re: run time error 1004 - method range of object worksheet failed.

    thanks gmr4evr1. now its working with the change.

    I have one more issue. please help me in that as well

    from the r sheet1, i need to clear the cells which is in b6:r11 - after copy paste.

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

    Re: run time error 1004 - method range of object worksheet failed.

    Add this after your copy paste line
    Please Login or Register  to view this content.
    This might be a better option
    Please Login or Register  to view this content.
    Last edited by gmr4evr1; 02-11-2016 at 07:52 PM. Reason: Added optional code.

  6. #6
    Registered User
    Join Date
    02-11-2016
    Location
    dubai
    MS-Off Ver
    msoffice 2010
    Posts
    75

    Re: run time error 1004 - method range of object worksheet failed.

    Dear gmr4evr1

    Now i required to add more cells to copy. i.e. i need to copy the cells b6:s18 and b18:b30. Need with two different range to copy. Please suggest

    Code given by you is as below.
    Set myCopy = Sheets("Sheet1").Range("B6:R11")

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

    Re: run time error 1004 - method range of object worksheet failed.

    See if this works
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    02-11-2016
    Location
    dubai
    MS-Off Ver
    msoffice 2010
    Posts
    75

    Re: run time error 1004 - method range of object worksheet failed.

    thanks. it is working.. now another one very basic formula required

    i have pasted the information below
    A B C D E F Result h Colum Result i column Q
    1 50000 maggie andrew sunil andrew maggie
    2 1000000 baby sugar mani sugar stews
    3 2000000 maggie sugar sunil sugar cars
    4 500000 toys chika tikka chika geo
    5 8000000 hakka gabriel mento gabriel toys


    My result columns are h and i
    If A column is greater than 200000 and if c CELL item is not matching with the p column listed items, then get the result E column
    If A column is greater than 200000 and if c CELL item is matching with the p column listed items, then get the result on I column

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

    Re: run time error 1004 - method range of object worksheet failed.

    Its not letting me post the formula to your thread

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

    Re: run time error 1004 - method range of object worksheet failed.

    In the attached is the formula in cell G1 and G2. See if it works
    anuswers formula.xlsx

  11. #11
    Registered User
    Join Date
    02-11-2016
    Location
    dubai
    MS-Off Ver
    msoffice 2010
    Posts
    75

    Re: run time error 1004 - method range of object worksheet failed.

    Dear gmr4evr1

    Below is the vba code where i copied and trying to have in excel with small changes of cell details and sheet details - Everything is working fine. The Change i am looking on the cells below.

    In below cells i have to write some data, otherwise my code will ask " hey you must write all the cells". What i required is, this cells should not be must in asking data when i run macro, it can be empty also in sheet2 in the below said cells.
    .
    also this empty cells should be copied in MISOUTWARD sheet

    B6:S18,B23:S30,AR15:AR27,AR34:AR41

    .
    VBA code - copied for your reference - Please support

    Sub MISOTTINPUT()
    '

    ' MISOTTINPUT Macro
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet

    Dim nextRow As Long
    Dim oCol As Long


    Dim myRng As Range
    Dim myCopy As Range
    Dim myCopy1 As Range
    Dim myCell As Range



    'cells to copy from Input sheet - some contain formulas
    Set myCopy = Sheets("Sheet2").Range("B6:S18,B23:S30,AR15:AR27,AR34:AR41")


    Set inputWks = Worksheets("Sheet2")
    Set historyWks = Worksheets("MISOUTWARD")

    With historyWks
    nextRow = .Cells(.Rows.Count, "E").End(xlUp).Offset(1, 0).Row
    End With



    With inputWks
    Set myRng = myCopy



    If Application.CountA(myRng) <> myRng.Cells.Count Then
    MsgBox "Hey you must write all the cells!"
    Exit Sub
    End If
    End With



    With historyWks
    With .Cells(nextRow, "C")
    .Value = Now
    .NumberFormat = "mm/dd/yyyy hh:mm:ss"
    End With
    .Cells(nextRow, "OM").Value = Application.UserName
    oCol = 4
    For Each myCell In myRng.Cells
    historyWks.Cells(nextRow, oCol).Value = myCell.Value
    oCol = oCol + 1
    Next myCell
    End With



    ' Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
    'Working in Excel 2002-2013
    Dim AWorksheet As Worksheet
    Dim Sendrng As Range
    Dim rng As Range

    On Error GoTo StopMacro

    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    End With

    'Fill in the Worksheet/range you want to mail
    'Note: if you use one cell it will send the whole worksheet
    Set Sendrng = Worksheets("Sheet2").Range("A1:I27")

    'Remember the activesheet
    Set AWorksheet = ActiveSheet

    With Sendrng

    ' Select the worksheet with the range you want to send
    .Parent.Select

    'Remember the ActiveCell on that worksheet
    Set rng = ActiveCell

    'Select the range you want to mail
    .Select

    ' Create the mail and send it
    ActiveWorkbook.EnvelopeVisible = True
    With .Parent.MailEnvelope

    ' Set the optional introduction field thats adds
    ' some header text to the email body.
    .Introduction = "These are the MIS recorded for the Outward Team"


    With .Item

    .To = "anuwers@gmail.com"


    .Subject = "Daily MIS of Number of TT's Processed and the Internal Errors"
    .Send
    End With

    End With

    'select the original ActiveCell
    rng.Select
    End With

    'Activate the sheet that was active before you run the macro
    AWorksheet.Select

    StopMacro:
    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

    'clear input cells that contain constants
    With inputWks
    On Error Resume Next
    With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
    .ClearContents
    Application.GoTo .Cells(1) ', Scroll:=True
    End With
    On Error GoTo 0
    End With

    'clear input cells that contain constants
    With inputWks
    On Error Resume Next
    With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
    .ClearContents
    Application.GoTo .Cells(1) ', Scroll:=True
    End With
    On Error GoTo 0
    End With

    Sheets("Sheet2").Range("B6:q18").Value = ""
    Sheets("Sheet2").Range("S6:S18").Value = ""




    Sheets("Sheet2").Select
    Range("B6").Select
    Range(Selection, Selection.End(xlDown)).Select


    End Sub

+ 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. Run-time error '1004': Method 'range' of object '_Global' failed
    By rubenidas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2016, 05:14 PM
  2. [SOLVED] Run-time error '1004' : Method 'Range' of object'_Global' failed
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2015, 09:47 AM
  3. [SOLVED] VBA | Advanced Filter | Run time error 1004 method range of object worksheet failed
    By williakm1013 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-05-2013, 08:30 PM
  4. [SOLVED] Error 1004 - Method Range of Object Worksheet Failed
    By mrbickelsworth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2013, 02:18 PM
  5. Run Time error 1004 Method Select of Object Worksheet failed
    By AlexMach in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-14-2012, 03:07 AM
  6. [SOLVED] Run time error 1004: method range of object _global failed
    By Danry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2012, 07:31 PM
  7. Run-time error '1004': Method 'Range' of object '_ Global' failed
    By mdvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2011, 11:48 AM

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