(Solved) – How to use a variable to select a row

(solved)-–-how-to-use-a-variable-to-select-a-row

I’m working on a Macro in Excel to take the data from 2 different departments and putting them into the same sheet to use the data for pivot tables. The data is automatically separated onto different sheets by departments when I run the report. The problem I keep running into is the amount of data (rows used) is always changing.

I’ve got it to a working point where I can get a variable set for that last row, but I cant figure out how to actually implement it. I might need to go one more row down from what it shows. I don’t know how I should go about that either. Here’s what I have for the affiliated code. Any advise would be great!

    Sheets("30A").Select
    Range("A1").Select
    Range("A1:O1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
With ActiveSheet
    Dim lastRow30A As Long
    lastRow30A = Sheet1.Range("A1048576").End(xlUp).Row
End With
    Sheets("40A").Select
    Range("A2:O2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A1").Select
    Range("lastRow30A").Select

Leave a Reply

Your email address will not be published. Required fields are marked *