VBA Research uses VBA to get the number of valid rows for any column in Excel

Source: Internet
Author: User

Iamlaosong

When using VBA to process Excel files, the key fields of the column number programming is often not known, need to pass parameter settings to know, therefore, when we program, we can not use such a statement to take the number of valid rows:

Lineno = [B65536]. End (Xlup). Row

The column name "B" in the above statement, if it is a variable, can be implemented in the form of a string connection, namely:

pos_ems = "C"
Lineno = Range (pos_ems & "65536"). End (Xlup). Row

If the column number is given, the following statement is used:

Pos_ems = 3
Lineno = Cells (65536, Pos_ems). End (Xlup). Row

The variable Pos_ems in the above statement can read the value of the cell so that it is ready to be set when confronted with different files:

    POS_FST = Cells (2, 7)    Pos_ems = Cells (3, 7)    Pos_sav = Cells (4, 7)        Lineno = [B65536]. End (Xlup). Row           ' number of files for        Unit_num = 5 to Lineno                 ' file loop            datfile = Cells (Unit_num, 2)                              ' file name        Datfullname = Thisworkbook.path & "\" & Datfile        If Dir (datfullname, vbnormal) <> vbNullString            Then Workbooks.Open filename:=datfullname        ' Open order file            If application.version >= ' 12.0 ' and Activeworkbook.fileformat =                MaxRow = Cells (1048576, Pos_ems). End (Xlup). Row            Else                maxrow = Cells (65536, Pos_ems). End (Xlup). Row            End If        Else            MsgBox "Data file does not exist!" ", vbOKOnly," Iamlaosong "            Exit Sub        End If
。。。




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

VBA Research uses VBA to get the number of valid rows for any column in Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.