ActiveSheets.Range("").Copy Method

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
136
Ok, so I am working on a macro seen below:

Sub Data_Parse()

Dim ER As Long

ER = ThisWorkbook.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

Dim Cell As Range
Dim CriteriaRange As Range


Set CriteriaRange = ThisWorkbook.ActiveSheet.Range("A3:A" & ER)
For Each Cell In CriteriaRange
If InStr(1, Cell.Value, "H04C", vbTextCompare) > 0 Then
Path_Name = Cell.Offset(columnOffset:=5).Value
File_Name = Path_Name & Cell.Value
Workbooks.Open Filename:=File_Name
ActiveSheets.Range("A6:K").Copy
ActiveWorkbook.Close
Workbooks("Example").Activate
Worksheets("Sheet 1").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).Select.PasteSpecial xlPasteValues, SkipBlanks:=False, Transpose:=True


End If
Next Cell

End Sub



My questions are how do I start the copy from row 6 through all used cells after? I would like to copy A6, B6, C6, etc. and all rows below without copying any information above row 6. Also, How do I paste such that it would start after the last used cell? Any input would be helpful, and Thank you.
 
Last edited:

Some videos you may like

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
13,886
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
First of all I would be surprised if the code you posted doesn't error out in at least 2 places.
Second, is your sheetname really Sheet 1 (with the space?)?

Anyway try the code below (untested)...

Rich (BB code):
Sub Data_Parse()

    Dim ER As Long

    ER = ThisWorkbook.ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

    Dim Cell As Range
    Dim CriteriaRange As Range

    Set CriteriaRange = ThisWorkbook.ActiveSheet.Range("A3:A" & ER)
    
    For Each Cell In CriteriaRange
        If InStr(1, Cell.Value, "H04C", vbTextCompare) > 0 Then
        
            Path_Name = Cell.Offset(, 5).Value
            File_Name = Path_Name & Cell.Value
            Workbooks.Open Filename:=File_Name
            
            With ActiveSheet.Range("A6:K" & ActiveSheet.Columns("A:K").Find("*", , xlValues, , xlByRows, xlPrevious).Row)
                Workbooks("Example").Worksheets("Sheet 1").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(.Rows.Count, .Columns.Count).Value = .Value
            End With
            
            ActiveWorkbook.Close
            
        End If
    Next Cell

End Sub
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,123,134
Messages
5,599,914
Members
414,348
Latest member
KloppyM

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
Top