+ Reply to Thread
Results 1 to 2 of 2

code will not find next complete empty row in data sheet

  1. #1
    Forum Contributor
    Join Date
    09-09-2014
    Location
    England
    MS-Off Ver
    2013
    Posts
    102

    code will not find next complete empty row in data sheet

    I have a command button that will populate a data sheet on the next empty row. However when I click the command button it re-writes over the top and bottom row of my data unless all data fields are used in the userform. This is my code:

    Private Sub CommandButton2_Click()
    Dim erow As Long

    With Sheet1
    erow = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    .Cells(erow, 1).Value = Stem1.Text
    .Cells(erow, 2).Value = Stem2.Text
    .Cells(erow, 3).Value = Val(NumberofPossibleResponses.Text)
    .Cells(erow, 4).Value = Response1.Text
    .Cells(erow, 5).Value = Response2.Text
    .Cells(erow, 6).Value = Response3.Text
    .Cells(erow, 7).Value = Response4.Text
    .Cells(erow, 8).Value = Response5.Text
    .Cells(erow, 9).Value = Response6.Text
    .Cells(erow, 10).Value = AnswerKey.Text
    .Cells(erow, 11).Value = ImageFile1Filename.Text
    .Cells(erow, 12).Value = Val(ImageFile1xcoordinate.Text)
    .Cells(erow, 13).Value = Val(ImageFile1ycoordinate.Text)
    .Cells(erow, 14).Value = Val(ImageFile1Scaling.Text)
    .Cells(erow, 15).Value = ImageFile2Filename.Text
    .Cells(erow, 16).Value = Val(ImageFile2xcoordinate.Text)
    .Cells(erow, 17).Value = Val(ImageFile2ycoordinate.Text)
    .Cells(erow, 18).Value = Val(ImageFile2Scaling.Text)
    .Cells(erow, 19).Value = Qualificationcmb.Text
    .Cells(erow, 20).Value = CurriculumTopicMain
    .Cells(erow, 21).Value = CurriculumAuxiliaryTopic1
    .Cells(erow, 22).Value = CurriculumAuxiliaryTopic2
    .Cells(erow, 23).Value = Val(TestID.Text)
    .Cells(erow, 24).Value = Val(ItemSequenceNumber.Text)
    .Cells(erow, 25).Value = Authors
    .Cells(erow, 26).Value = QuestionType
    .Cells(erow, 27).Value = Val(Weighting.Text)
    .Cells(erow, 28).Value = Val(LevelOfDemand.Text)
    .Cells(erow, 29).Value = EditorReviewer
    .Cells(erow, 30).Value = Val(Version.Text)
    .Cells(erow, 31).Value = StatusInLifecycle
    .Cells(erow, 32).Value = StageOfDevelopment
    .Cells(erow, 33).Value = AuthorNote
    .Cells(erow, 34).Value = IPRCopyrightNote
    .Cells(erow, 35).Value = ItemTitle
    .Cells(erow, 36).Value = Context
    .Cells(erow, 37).Value = TranslatorReviewer
    .Cells(erow, 38).Value = StageOfDevelopmentWorkflow
    .Cells(erow, 39).Value = EnemyItems
    .Range("a2").Value = Stem1
    .Range("b2").Value = Stem2
    .Range("c2").Value = NumberofPossibleResponses
    .Range("d2").Value = Response1
    .Range("e2").Value = Response2
    .Range("f2").Value = Response3
    .Range("g2").Value = Response4
    .Range("h2").Value = Response5
    .Range("i2").Value = Response6
    .Range("j2").Value = AnswerKey
    .Range("k2").Value = ImageFile1Filename
    .Range("l2").Value = ImageFile1xcoordinate
    .Range("m2").Value = ImageFile1ycoordinate
    .Range("n2").Value = ImageFile1Scaling
    .Range("o2").Value = ImageFile2Filename
    .Range("p2").Value = ImageFile2xcoordinate
    .Range("q2").Value = ImageFile2ycoordinate
    .Range("r2").Value = ImageFile2Scaling
    .Range("s2").Value = Qualificationcmb
    .Range("t2").Value = CurriculumTopicMain
    .Range("u2").Value = CurriculumAuxiliaryTopic1
    .Range("v2").Value = CurriculumAuxiliaryTopic2
    .Range("w2").Value = Val(TestID.Text)
    .Range("x2").Value = Val(ItemSequenceNumber.Text)
    .Range("y2").Value = Authors
    .Range("z2").Value = QuestionType
    .Range("aa2").Value = Val(Weighting.Text)
    .Range("ab2").Value = Val(LevelOfDemand.Text)
    .Range("ac2").Value = EditorReviewer
    .Range("ad2").Value = Val(Version.Text)
    .Range("ae2").Value = StatusInLifecycle
    .Range("af2").Value = StageOfDevelopment
    .Range("ag2").Value = AuthorNote
    .Range("ah2").Value = IPRCopyrightNote
    .Range("ai2").Value = ItemTitle
    .Range("aj2").Value = Context
    .Range("ak2").Value = TranslatorReviewer
    .Range("al2").Value = StageOfDevelopmentWorkflow
    .Range("am2").Value = EnemyItems
    End With

    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: code will not find next complete empty row in data sheet

    Hi, zak.horrocks,

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

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/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)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ 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. Replies: 1
    Last Post: 05-21-2014, 05:05 AM
  2. [SOLVED] Code that copies row of data to another sheet based on text "Complete"/"Delete"
    By Dremzy in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 04-20-2014, 05:51 PM
  3. [SOLVED] Vb code To Find the missing triplets and complete the number series..?
    By sem in forum Excel Programming / VBA / Macros
    Replies: 43
    Last Post: 05-31-2012, 02:48 PM
  4. How to find a row in a sheet and compare the complete row /w origi
    By Jazz - Netherlands in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-29-2006, 05:30 AM
  5. [SOLVED] I need to find the first empty row in a sheet to paste data to
    By rgbivens in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2005, 03:06 PM

Tags for this Thread

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