+ Reply to Thread
Results 1 to 6 of 6

offset function not populating - run time 1004 error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    offset function not populating - run time 1004 error

    HR1 is a defined file path to spreadsheet, HR is the name of the Userform, Initials is the name of the textbox within HR.

    I am attempting to move down column C if C4 is not empty until I find the last full cell then move down to the empty one below it however I keep getting an error on the last row of the code. Can anyone tell me what I am doing wrong as it's driving me crazy?

    Error message is "Application-defined or object-defined error", still trying to understand these error messages.


        ElseIf HR1.Range("C4") <> "" Then
        
           HR1.Range("C4").Select
                Selection.End(xlDown).Select
                    ActiveCell.Offset(1, 0).Value = HR.Initials.Value & "001"

  2. #2
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: offset function not populating - run time 1004 error

    This is the full code if it helps

    Private Sub CommandButton1_Click()
    
    HR.Birth.Text = Format(SetUp.PSD.Text, "d mm yyyy")
    HR.NI.Text = Format(HR.NI.Text, "## ## ## ## #")
    HR.Sort.Text = Format(HR.Sort.Text, "##-##-##")
    HR.Salary.Text = Format(HR.Salary.Text, "£0.00")
    
        '   SPath needs to be changed to the filepath for the main computer computer
        
        '   HR Database Path
    Dim FPath As Workbook
    Dim SUPath As Worksheet
    Set FPath = Workbooks.Open("C:\Users\Scott\Documents\CMC\Database.xlsm")
    Set HR1 = FPath.Worksheets("HR")
    
    Application.ScreenUpdating = False
    
    If HR1.Range("C4") = "" Then
        HR1.Range("C4").Value = HR.Initials.Value & "001"
        
    HR1.Range("D4").Value = HR.Job.Text
    HR1.Range("F4").Value = HR.Birth.Text
    HR1.Range("G4").Value = HR.Salutation.Text
    HR1.Range("H4").Value = HR.Forename.Text
    HR1.Range("I4").Value = HR.MiddleName.Text
    HR1.Range("J4").Value = HR.Surname.Text
    HR1.Range("K4").Value = HR.House.Text
    HR1.Range("L4").Value = HR.Street.Text
    HR1.Range("M4").Value = HR.Town.Text
    HR1.Range("N4").Value = HR.County.Text
    HR1.Range("O4").Value = HR.PostCode.Text
    HR1.Range("P4").Value = HR.Tel.Text
    HR1.Range("Q4").Value = HR.EmCon.Text
    HR1.Range("R4").Value = HR.Rel.Text
    HR1.Range("S4").Value = HR.EmConTel.Text
    HR1.Range("T4").Value = HR.NI.Text
    HR1.Range("U4").Value = HR.Tax.Text
    HR1.Range("V4").Value = HR.Bank.Text
    HR1.Range("W4").Value = HR.Sort.Text
    HR1.Range("X4").Value = HR.ACC.Text
    HR1.Range("Y4").Value = HR.Salary.Text
    
        ElseIf HR1.Range("C4") <> "" Then
        
           HR1.Range("C4").Select
                Selection.End(xlDown).Select
                    ActiveCell.Offset(1, 0).Value = HR.Initials.Value & "001"
                
                
    ActiveCell.Offset(0, 1).Value = HR.Job.Text
    ActiveCell.Offset(0, 3).Value = HR.Birth.Text
    ActiveCell.Offset(0, 4).Value = HR.Salutation.Text
    ActiveCell.Offset(0, 5).Value = HR.Forename.Text
    ActiveCell.Offset(0, 6).Value = HR.MiddleName.Text
    ActiveCell.Offset(0, 7).Value = HR.Surname.Text
    ActiveCell.Offset(0, 8).Value = HR.House.Text
    ActiveCell.Offset(0, 9).Value = HR.Street.Text
    ActiveCell.Offset(0, 10).Value = HR.Town.Text
    ActiveCell.Offset(0, 11).Value = HR.County.Text
    ActiveCell.Offset(0, 12).Value = HR.PostCode.Text
    ActiveCell.Offset(0, 13).Value = HR.Tel.Text
    ActiveCell.Offset(0, 14).Value = HR.EmCon.Text
    ActiveCell.Offset(0, 15).Value = HR.Rel.Text
    ActiveCell.Offset(0, 16).Value = HR.EmConTel.Text
    ActiveCell.Offset(0, 17).Value = HR.NI.Text
    ActiveCell.Offset(0, 18).Value = HR.Tax.Text
    ActiveCell.Offset(0, 19).Value = HR.Bank.Text
    ActiveCell.Offset(0, 20).Value = HR.Sort.Text
    ActiveCell.Offset(0, 21).Value = HR.ACC.Text
    ActiveCell.Offset(0, 22).Value = HR.Salary.Text
        End If
                
    HR.Hide
    FPath.Save
    FPath.Close
    
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: offset function not populating - run time 1004 error

    The problem is probably because with xlDown you are going right to the last row in the sheet, and then with the Offset trying to move one row beyond.

    Where do you want the data to go?

    Do you have header rows, for example in row 3?
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: offset function not populating - run time 1004 error

    yes, header rows in row 3, data input from row 4 downwards. Want to find the last row with data (below row 4) and insert data below it.

    I tried range ("C:C"),xlup but that didn't work either

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: offset function not populating - run time 1004 error

    Try this.
    With HR1.Range("C" & Rows.Count).End(xlUp).Offset(1)           
        .Value = HR.Initials.Value & "001"        
        .Offset(0, 1).Value = HR.Job.Text
        .Offset(0, 3).Value = HR.Birth.Text
        .Offset(0, 4).Value = HR.Salutation.Text
        .Offset(0, 5).Value = HR.Forename.Text
        .Offset(0, 6).Value = HR.MiddleName.Text
        .Offset(0, 7).Value = HR.Surname.Text
        .Offset(0, 8).Value = HR.House.Text
        .Offset(0, 9).Value = HR.Street.Text
        .Offset(0, 10).Value = HR.Town.Text
        .Offset(0, 11).Value = HR.County.Text
        .Offset(0, 12).Value = HR.PostCode.Text
        .Offset(0, 13).Value = HR.Tel.Text
        .Offset(0, 14).Value = HR.EmCon.Text
        .Offset(0, 15).Value = HR.Rel.Text
        .Offset(0, 16).Value = HR.EmConTel.Text
        .Offset(0, 17).Value = HR.NI.Text
        .Offset(0, 18).Value = HR.Tax.Text
        .Offset(0, 19).Value = HR.Bank.Text
        .Offset(0, 20).Value = HR.Sort.Text
        .Offset(0, 21).Value = HR.ACC.Text
        .Offset(0, 22).Value = HR.Salary.Text
    End With
    Note with this code you really wouldn't need the If that's checking if there is data in row 4.

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: offset function not populating - run time 1004 error

    You the man Norie, cheers

+ 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. [SOLVED] "Run-time error '1004': App-dfnd or objt-dfnd err" Debug highlights ActiActiveCell.offset
    By GMAGANA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-29-2014, 03:25 PM
  2. Run time error '1004' when populating pivot table
    By Orongo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-22-2012, 07:29 AM
  3. Run time error 1004 unable to get the vlookup property of the worksheet function class
    By surajitbose in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2012, 06:12 PM
  4. 'Run time error '1004' on ActiveCell.Offset(1, 0).Select
    By perbags in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-02-2010, 01:37 PM
  5. range.offset generates a Run Time error 1004
    By nospamretmster@googlemail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2006, 12:50 PM

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