VBA code edit help please - open file paste content below last row sheet close and open next repeat

roberttkim

Board Regular
Joined
Mar 5, 2009
Messages
97
Hi everyone. Wondering if someone can help me edit this code. Really appreciate it. The code below opens an html file saved on network drive location in a cell B2 and copy pastes the content of that file to sheet data. It then opens another file based on location in cell B3 and copy pastes the content to the sheet data. However, i need it copy and paste it to the last row with no data on the data sheet instead of overwriting everything. The last piece of code closes all the html files opened. Please help.

VBA Code:
Dim NmStr As String
NmStr = ActiveWorkbook.Name
Windows(NmStr).Activate

Report = Sheets("RECON").Range("B2").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste


Report = Sheets("RECON").Range("B3").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste



Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A2").Value).Close False
Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A3").Value).Close False
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
.
See if this works :

VBA Code:
Dim NmStr As String
NmStr = ActiveWorkbook.Name
Windows(NmStr).Activate

Report = Sheets("RECON").Range("B2").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste


Report = Sheets("RECON").Range("B3").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
'Range("A1").Select
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)



Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A2").Value).Close False
Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A3").Value).Close False
 
Upvote 0
.
See if this works :

VBA Code:
Dim NmStr As String
NmStr = ActiveWorkbook.Name
Windows(NmStr).Activate

Report = Sheets("RECON").Range("B2").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste


Report = Sheets("RECON").Range("B3").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
'Range("A1").Select
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)



Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A2").Value).Close False
Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A3").Value).Close False
.
See if this works :

VBA Code:
Dim NmStr As String
NmStr = ActiveWorkbook.Name
Windows(NmStr).Activate

Report = Sheets("RECON").Range("B2").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste


Report = Sheets("RECON").Range("B3").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
'Range("A1").Select
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)



Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A2").Value).Close False
Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A3").Value).Close False

Thanks but when i try to add
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
it says compile error
 
Upvote 0
.
????

VBA Code:
Option Explicit

Sub cpyPaste()

Dim NmStr As String, Report As String
NmStr = ActiveWorkbook.Name
Windows(NmStr).Activate

Report = Sheets("RECON").Range("B2").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
Windows(NmStr).Activate
Sheets("Data").Select
Range("A1").Select
ActiveSheet.Paste

Report = Sheets("RECON").Range("B3").Value
Workbooks.Open Filename:=Report
ActiveSheet.Cells.Copy
ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
'Windows(NmStr).Activate
'Sheets("Data").Select
'Range("A1").Select

Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A2").Value).Close False
Workbooks.Application.CutCopyMode = False
Workbooks(Sheets("RECON").Range("A3").Value).Close False

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,039
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top