+ Reply to Thread
Results 1 to 5 of 5

keep getting Runtime error 1004 in my VBA Macro and not sure why

  1. #1
    Forum Contributor
    Join Date
    10-03-2015
    Location
    Jamaica
    MS-Off Ver
    2013
    Posts
    120

    keep getting Runtime error 1004 in my VBA Macro and not sure why

    Hey guys hope i can get some help this issue i am having. first of i am a bit of a novice with excel so its no wonder i cant locate the error here is the scenario.

    I wrote a macro that would automatically update data from one sheet into another work sheet when I entered information and clicked update. When I enter information and click update the info is entered into the first row under the header no problem, but it does not automatically go to the next row, so when i try to enter the next series of info i get the run-time error. please see below a copy of the code


    Private Sub CommandButton1_Click()
    Dim StudentFirstName As String, StudentLastName As String, StudentGender As String, StudentGrade As String, StudentIdAssigned As String, DateAssigned As String
    Worksheets("Sheet1").Select
    StudentFirstName = Range("C5")
    StudentLastName = Range("C6")
    StudentGender = Range("C7")
    StudentGrade = Range("C8")
    StudentIdAssigned = Range("C9")
    DateAssigned = Range("C10")
    Worksheets("Sheet2").Select
    Worksheets("Sheet2").Range("A9").Select
    If Worksheets("Sheet2").Range("A9").Offset(1, 0) <> "" Then
    Worksheets("Sheet2").Range("A9").End(x1Down).Select
    End If
    ActiveCell.Offset(1, 0).Select
    ActiveCell.Value = StudentFirstName
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = StudentLastName
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = StudentGender
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = StudentGrade
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = StudentIdAssigned
    ActiveCell.Offset(0, 1).Select
    ActiveCell.Value = DateAssigned
    Worksheets("Sheet1").Select
    Worksheets("Sheet1").Range("C5").Select
    Worksheets("Sheet1").Range("C5:C10").ClearContents


    Debugging always identifies this line of code as the culprit Worksheets("Sheet2").Range("A9").End(x1Down).Select
    but i cant figure out why.

    any help in this regard would be much appreciated.

  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: keep getting Runtime error 1004 in my VBA Macro and not sure why

    It should be
    Please Login or Register  to view this content.
    Instead of
    Please Login or Register  to view this content.
    You have 1 instead of l
    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 Contributor
    Join Date
    10-03-2015
    Location
    Jamaica
    MS-Off Ver
    2013
    Posts
    120

    Re: keep getting Runtime error 1004 in my VBA Macro and not sure why

    WOW your right.

    Thanks a lot gmr4evr1

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: keep getting Runtime error 1004 in my VBA Macro and not sure why

    If you put Option Explicit at the top of every module, you'll never have that problem again.
    Entia non sunt multiplicanda sine necessitate

  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: keep getting Runtime error 1004 in my VBA Macro and not sure why

    You're welcome, glad I was able to help.
    As for what shg posted, DEFINATELY use Option Explicit, it's saved me a lot of time trying to figure out why the "perfect" code I'm using is giving me errors.

+ 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. Runtime Error 1004 on list creating macro
    By taipalam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2014, 04:13 AM
  2. [SOLVED] Runtime error 1004. the macro may not be available in this workbook or all macros may....
    By ddander54 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-29-2012, 08:46 AM
  3. Runtime error 1004 using macro in excel 2007
    By CrazyHorse in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2011, 11:54 AM
  4. Macro - Runtime Error 1004
    By Evian in forum Excel Charting & Pivots
    Replies: 10
    Last Post: 10-08-2008, 04:54 AM
  5. Using a macro to put a function in a certain cell (runtime error 1004)
    By Juhanen II in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-30-2007, 10:29 AM
  6. [SOLVED] Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM
  7. naming tab macro error runtime error 1004
    By D in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2005, 10:06 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