+ Reply to Thread
Results 1 to 4 of 4

Obtain COUNTA value in row of data, and place in Textbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Obtain COUNTA value in row of data, and place in Textbox

    I am trying to obtain No. of used cells between columns 'L - AP" Column #(12-42) in the below code, but i only ever get a value of 1??
    With current data, i should get a 6.

    Private Sub ListBox1_Click()
    Dim lastcell
    Dim myrow
    Sheets("SB_DATA").Visible = True
    lastcell = Worksheets("SB_DATA").Cells(Rows.Count, "B").End(xlUp).Row
    With ActiveWorkbook.Worksheets("SB_DATA")
    .Select
        For myrow = 1 To lastcell
        If .Cells(myrow, 2) <> "" And Me.ListBox1.Value = .Cells(myrow, 2).Value Then ' Listbox has a value that is found in Column B(2) to set the row of data required to work with
              Me.TextBox2.Value = .Cells(myrow, 165).Value
              Me.TextBox4.Value = Application.WorksheetFunction.CountA(.Cells(myrow, 12), .Cells(myrow, 42)) ' <---- Trying to obtain No. of used cells between columns 'L - AP"
                 End If
        Next
    End With
    End Sub

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,337

    Re: Obtain COUNTA value in row of data, and place in Textbox

    How about this ?

    Private Sub ListBox1_Click()
        Dim myrow As Long
        Sheets("SB_DATA").Visible = True
        With Sheets("SB_DATA")
            myrow = Application.Match(listbox1.Value, .Columns(2), 0)
            If Not IsError(myrow) Then
                TextBox2.Value = .Cells(myrow, 165).Value
                TextBox4.Value = Application.CountA(.Cells(myrow, 12).Resize(, 30))
            End If
        End With
    End Sub
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Obtain COUNTA value in row of data, and place in Textbox

    Thanks bakerman2, perfect.
    I can work with that as is.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,337

    Re: Obtain COUNTA value in row of data, and place in Textbox

    You're welcome and thanks for rep+.

+ 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. Userform textbox output to one decimal place
    By Tubes2015 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2015, 11:12 AM
  2. Place Textbox Value to the next empty cell
    By weeeee0713 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2014, 04:20 AM
  3. [SOLVED] Trouble with getting a checkbox to place a cell value when matching the textbox.
    By Templemind in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-16-2014, 02:57 PM
  4. Userform to search textbox value to place other textbox values in worksheet
    By mattyh555 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 11:38 AM
  5. [SOLVED] Cannot place a picture again in another textbox
    By Yogi28 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2012, 10:44 PM
  6. [SOLVED] Place data from VBA Userform TextBox into a new row on a worksheet every time
    By Sugarray in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2012, 08:51 AM
  7. Userform Textbox to obtain value of a cell from another workbook
    By Astroboy142 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2010, 08:39 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