VBA Row Number Adjustment

HazatB

New Member
Joined
Sep 19, 2017
Messages
32
Hi,

I have had help in earlier threads but kind of caused confusion with what I was asking so I started a new thread to properly ask for assistance.

I have created this macro below which has accomplished my desired task of copying data from one workbook into another, however, I need to figure out if there is a way to adjust for the number of rows whether there is less or more.


Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A1:E6651").Copy
Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("A7:E6657").PasteSpecial

Application.CutCopyMode = False

Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("F1:G6651").Copy
Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("I7:J6657").PasteSpecial

Application.CutCopyMode = False

any assistance would be appreciated.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Not sure exactly what you want by your description but try (untested)...

Code:
Sub Test()
    Dim LastRow As Long
    LastRow = Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A:G").Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row

    Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A1:E" & LastRow).Copy _
            Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("A7")


    Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("F1:G" & LastRow).Copy _
            Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("I7")

End Sub
 
Upvote 0
Not sure exactly what you want by your description but try (untested)...

Code:
Sub Test()
    Dim LastRow As Long
    LastRow = Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A:G").Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row

    Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A1:E" & LastRow).Copy _
            Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("A7")


    Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("F1:G" & LastRow).Copy _
            Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("I7")

End Sub

This nearly worked for me, to clarify what I need to do is copy data from one workbook that is from a converted text file and paste this information into my master workbook which I was able to figure out. My main goal now is to be able to add or delete the number of rows based on the new data taken from my text file.
 
Upvote 0
Nope, still not sure exactly what you want but as some guesses for the first part of your code (and again untested so expect errors)...

Code:
Sub Test2()
    Dim LastRow As Long, x As Long, y As Long
    LastRow = Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A:G").Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row
    
    With Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A1:E" & LastRow)
        x = .Rows.Count
        y = .Columns.Count
    End With

    Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("A7").Resize(x, y).Delete

End Sub


or

Code:
Sub Test3()
    Dim LastRow As Long, x As Long
    LastRow = Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A:G").Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row
    
    x = Workbooks("before_n_after_remap_audit_umroi.txt").Worksheets("before_n_after_remap_audit_umro").Range("A1:E" & LastRow).Rows.Count

    Workbooks("UMROI_Standard Cost Audit Reports.xlsm").Worksheets("Before n After Remap Review").Range("A7").Resize(x).EntireRow.Delete

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,633
Latest member
DougMo

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