ActiveSheets.Range("").Copy Method

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
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:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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