Home > Computer Tutorials > Computer Knowledge > Using VBA, write data to the last row and first column of another Excel file

Using VBA, write data to the last row and first column of another Excel file

王林
Release: 2024-01-24 10:00:08
forward
856 people have browsed it

Using VBA, write data to the last row and first column of another Excel file

vba writes data to the last row of the first column in another xls file

In the opened A.XLSX, copy C3 and paste it into the cell in the first column and the last row of B. The procedure is as follows:

Sub macro 1()

Range("C3").Select 'Select C3

Selection.Copy 'Copy

Windows("B.xlsx").Activate 'Select the B.XLSX workbook

lastrow = Cells(Rows.Count, 1).End(3).Row 'Find the last row of the first column

Cells(lastrow, 1).Select 'Select the cells in the last row of the first column

ActiveSheet.Paste 'Paste

cells(1,1)=Cells(lastrow, 3) 'Read the value in the third column of the current row and write it into the first cell of the current xls table

Windows("A.xlsx").Activate 'Return to XLSX

End Sub

How to use vba in excel to get the last column of the first row

Sub Test004()

Dim CoLumn_Num As String

Dim Num As Long

Num = Range("IV1").End(xlToLeft).Column

If Num

CoLumn_Num = Chr(64 Num)

ElseIf Num Mod 26 = 0 Then

CoLumn_Num = Chr(63 Num \ 26) & Chr(90)

Else

CoLumn_Num = Chr(64 Num \ 26) & Chr(64 (Num) Mod 26)

End If

MsgBox "First row and last column:" & CoLumn_Num & "Column"

End Sub

Has been tested, feel free to use

The above is the detailed content of Using VBA, write data to the last row and first column of another Excel file. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template