I always get either automation error or run-time error. I will appreciate anyone's help. I can't figure out how to solve the line,
wb.Worksheets("Sheet1").Range("A" & i).Value = wb2.Worksheets("tc1").Range("A" & i).Value
The whole code can be seen below:
Option Explicit
Public Sub Button1_Click()
Dim wb As Workbook, wb2 As Workbook
Dim ws As Worksheet
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
Set wb2 = ActiveWorkbook
Dim lngWriteRow As Long
lngWriteRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Dim lastna As String
lastna = "A" + Str(lngWriteRow)
lngWriteRow = Replace(lngWriteRow, " ", "")
Dim i As Integer
i = 2
Do
wb.Worksheets("Sheet1").Range("A" & i).Value = wb2.Worksheets("tc1").Range("A" & i).Value
ActiveWorkbook.Close savechanges:=True
i = i + 1
While i < lngWriteRow
Wend
Loop
End Sub
Thank you!!!
wb.Worksheets("Sheet1").Range("A" & i).Value = wb2.Worksheets("tc1").Range("A" & i).Value
The whole code can be seen below:
Option Explicit
Public Sub Button1_Click()
Dim wb As Workbook, wb2 As Workbook
Dim ws As Worksheet
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
1, "Select One File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
Set wb2 = ActiveWorkbook
Dim lngWriteRow As Long
lngWriteRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
Dim lastna As String
lastna = "A" + Str(lngWriteRow)
lngWriteRow = Replace(lngWriteRow, " ", "")
Dim i As Integer
i = 2
Do
wb.Worksheets("Sheet1").Range("A" & i).Value = wb2.Worksheets("tc1").Range("A" & i).Value
ActiveWorkbook.Close savechanges:=True
i = i + 1
While i < lngWriteRow
Wend
Loop
End Sub
Thank you!!!