Results 1 to 4 of 4
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Last Row Count, Last Column Name and Number

    I can find all sorts of ways to do this in excel, but not in Access. Getting the Excel file inported is easy:



    Code:
    Option Explicit
    Private Sub Start_Click()
    
    
    Dim rS As DAO.Recordset
    Dim F As Object
    Dim VarItem As Variant
    Dim c As Integer
    Dim Last_Row_Num As Long, Last_Col_Num As Long
    Dim Last_Col As String, , strFile As String
    
    Set F = Application.FileDialog(1)
           F.AllowMultiSelect = False
        
        If F.Show Then
            For Each VarItem In F.SelectedItems
                strFile = Dir(VarItem)
                strFolder = Left(VarItem, Len(VarItem) - Len(strFile))
            Next
        End If
    
     DoCmd.TransferSpreadsheet 0, acSpreadsheetTypeExcel12, "Data", strFile, 1
    
    For c = 2 To Last_Col_Num
            If Data.ColHeaders(1, c) = "Unit" Then 
                col_BN = c
            End If
    
    If Data.ColHeaders(1, c) = "TOE Title" Then col_Co = c End If...………………………….
    Next c
    I am trying to convert:
    Code:
    Last_Col_Num = ActiveSheet.Range("A1").SpecialCells(xlCellTypeLastCell).Column  'this gets the last column by number
    Last_Col = Split(Cells(1, Last_Col_Num).Address, "$")(1)  'this gets the column letter
    Last_Row = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row 'Finds last cell in Column B with data.
    Into Access VBA

    Dlast?

    Its easy to do in a query with
    Col 1: Data.Unit As BN
    Col 2: Data.[TOE Title] as CO

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Dcount("*","[Data]") or CurrentDb.TableDefs("Data").RecordCount would give you the number of "rows" (=records) and CurrentDb.TableDefs("Data").Fields.Count would give you the column count (fields).

    Cheers,
    Vlad

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    Thanks Gicu,
    I used the current......count worked like a charm. I figured I didn't need the String for the fieldnames and did it another way.

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You're welcome!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 12-02-2017, 02:32 PM
  2. Number of Data Count in Each column of a table
    By Blessy clara in forum Queries
    Replies: 1
    Last Post: 04-04-2017, 02:30 PM
  3. Replies: 3
    Last Post: 03-02-2015, 09:50 AM
  4. Replies: 4
    Last Post: 10-15-2014, 05:51 AM
  5. Replies: 1
    Last Post: 01-24-2013, 05:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums