+ Reply to Thread
Results 1 to 6 of 6

Line Count Code

  1. #1
    Registered User
    Join Date
    03-05-2013
    Location
    Wichita, KS, USA
    MS-Off Ver
    Excel 2010
    Posts
    17

    Line Count Code

    I have code that I developed to input data from an userform into a worksheet line by line. I am using a command add button to input the data, and the only thing that I can't get to work is a line count such as 1, 2, 3, 4, ....

    What is some easy code that I can add within the command add sub routine?

    Thanks,

    James

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

    Re: Line Count Code

    James

    Can you post the code you are using to input the data?

    PS Please use code tags.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    03-05-2013
    Location
    Wichita, KS, USA
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Line Count Code

    This is what I have so far...

    Private Sub cmdAdd_Click()

    Application.ScreenUpdating = False

    Dim i As Integer
    Dim emptyRow As Long
    Dim ws As Worksheet

    Set ws = Worksheets("Chassis Report Record")

    'position cursor in the correct cell B3
    Range("B3").Select
    i = 1 'set as the first ID

    'Determine emptyRow
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

    Do Until ActiveCell.Value = Empty
    ActiveCell.Offset(1, 0).Select 'move down 1 row
    i = i + 1 'keep a count of the ID for later use
    Loop

    'Export Data to worksheet - Populate the new data values into the 'Data' worksheet.
    ActiveCell.Value = i 'Next ID number
    ActiveCell.Offset(0, -1).Value = Range("A3").Value + 1 'set col A - Counts the number of inpsections
    ActiveCell.Offset(0, 0).Value = Me.txtChassisTagNo.Text 'set col B - Chassis tag number
    ActiveCell.Offset(0, 1).Value = Me.txtDate.Text 'set col C - Date
    ActiveCell.Offset(0, 2).Value = Me.txtName.Text 'set col D - name of racer/owner
    ActiveCell.Offset(0, 8).Value = Me.txtDriveTime.Text 'set col J - drive time fee charged (usually NA)
    ActiveCell.Offset(0, 9).Value = Me.txtMileage.Text 'set col K - mileage charged
    ActiveCell.Offset(0, 12).Value = Me.txtCheck.Text 'set col N - Check number - if payment was by check

    'resets the data back to initial userform state
    txtChassisTagNo.Value = ""
    txtDate.Value = "mm/dd/yyyy"
    txtName.Value = ""
    txtMileage.Value = ""
    txtDriveTime.Value = "0"
    txtCheck.Value = "------"
    txtTagPrice.Value = ""
    txtServiceFee.Value = ""
    txtAmount.Value = ""
    txtTotalAmount.Value = ""
    OptionButtonHousecalls.Value = False
    OptionButtonEvent.Value = False
    OptionButtonSeminar.Value = False
    OptionButtonSportsman.Value = False
    OptionButtonPro.Value = False
    OptionButtonExhibition.Value = False
    OptionButtonPass.Value = False
    OptionButtonFail.Value = False
    OptionButtonCash.Value = False
    OptionButtonCheck.Value = False

    With txtChassisTagNo
    .Text = "A000000"
    .SelStart = 0
    .SelLength = Len(.Text)
    .SetFocus
    End With

    Application.ScreenUpdating = True
    End Sub

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

    Re: Line Count Code

    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

  5. #5
    Registered User
    Join Date
    03-05-2013
    Location
    Wichita, KS, USA
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Line Count Code

    This is my code so far. The counter that I am using is in the CommandAdd.
    Attached Files Attached Files

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,316

    Re: Line Count Code

    Please comply with the request in post #4 before we can move on...
    HTH
    Regards, Jeff

+ 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] for every line I browse make a count and post this count in a cell (fiouuu)
    By historic777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2013, 06:41 AM
  2. [SOLVED] SQL Code does not fit in one line in Excel VBA, automatically moves down one line
    By trizzo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-11-2013, 10:56 AM
  3. [SOLVED] help - count code in worksheet1 & place count in worksheet2 next to appropriate code#
    By burnettec in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-30-2012, 05:09 PM
  4. [SOLVED] Save Data code not saving to the next line, keeps overwriting to same line.
    By Justin25150 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2012, 06:40 AM
  5. Continue line of VBA code on the next line
    By peacelittleone in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-24-2005, 03:05 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