+ Reply to Thread
Results 1 to 7 of 7

Run-Time error 1004 when trying to run Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    02-06-2014
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    25

    Run-Time error 1004 when trying to run Macro

    Hi all, I'm getting the error 1004 whilst running this macro. It was working fine earlier, any advice would be much appreciated.

    
    Sub DateFormat()
    
    ' converts dates from dd.mm.yy format to dd/mm/yy format
    
    Dim LastRow As Integer
    
     jLastRow = Sheets("Data").UsedRange.Rows.Count
     
        Columns("J:J").Select
        
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        
        Range("J1").Select
        ActiveCell.FormulaR1C1 = "=REPLACE(RC[-1],3,1,""/"")"
        Selection.AutoFill Destination:=Range(Cells(1, 10), Cells(jLastRow, 10))
        
        Range("K1").Select
        ActiveCell.FormulaR1C1 = "=REPLACE(RC[-1],6,1,""/"")"
        Selection.AutoFill Destination:=Range(Cells(1, 11), Cells(jLastRow, 11))
    
    Call GetDays
    
    End Sub

    The error occurs on the line: "Selection.AutoFill Destination:=Range(Cells(1, 10), Cells(jLastRow, 10))"




    Thanks,

    Matt
    Last edited by Matt2014; 03-31-2014 at 06:55 AM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,054

    Re: Run-Time error 1004 when trying to run Macro

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    02-06-2014
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Run-Time error 1004 when trying to run Macro

    Apologies done now

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Run-Time error 1004 when trying to run Macro

    Hi,

    the selected cell (bad way, better without using any Select in code …)
    must be the fisrt cell in the AutoFill range …

  5. #5
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Run-Time error 1004 when trying to run Macro

    I think it is easier not to autofill:
        Range("J1:J" & jLastRow).FormulaR1C1 = "=REPLACE(RC[-1],3,1,""/"")"
        Range("K1:K" & jLastRow).FormulaR1C1 = "=REPLACE(RC[-1],6,1,""/"")"
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  6. #6
    Registered User
    Join Date
    02-06-2014
    Location
    London,England
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: Run-Time error 1004 when trying to run Macro

    Hi Izandol,

    Thanks for your advice. I'm new to all this so is what you've given me is that to replace the "Selection.AutoFill Destination:=Range(Cells(1, 10), Cells(jLastRow, 10))"

    Thanks,

    Matt

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Run-Time error 1004 when trying to run Macro

    This code will replace these lines:
        Range("J1").Select
        ActiveCell.FormulaR1C1 = "=REPLACE(RC[-1],3,1,""/"")"
        Selection.AutoFill Destination:=Range(Cells(1, 10), Cells(jLastRow, 10))
        
        Range("K1").Select
        ActiveCell.FormulaR1C1 = "=REPLACE(RC[-1],6,1,""/"")"
        Selection.AutoFill Destination:=Range(Cells(1, 11), Cells(jLastRow, 11))

+ 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. Excel Macro Error - Run time error 1004 - Paste method of worksheet class failed
    By kvflynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2012, 10:51 AM
  2. Macro Run-time error '1004':
    By Kody_Devl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-24-2012, 03:09 PM
  3. Run-time error '1004': Macro error, only when shared
    By Pergo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 12:57 PM
  4. Excel 2007 : Macro run-time error 1004
    By tuph in forum Excel General
    Replies: 4
    Last Post: 11-23-2009, 07:04 PM
  5. MACRO Run Time Error 1004
    By The Toasterman in forum Excel General
    Replies: 1
    Last Post: 06-30-2006, 11:25 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