Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:03:33+00:00 2026-06-04T09:03:33+00:00

Here is my script. Sub Update_OOR() Dim wsTNO As Worksheet Dim wsTND As Worksheet

  • 0

Here is my script.

Sub Update_OOR()

    Dim wsTNO As Worksheet
    Dim wsTND As Worksheet
    Dim wsTNA As Worksheet
    Dim lastrow As Long, fstcell As Long

    Set wsTNO = Sheets("Tel-Nexx OOR")
    Set wsTND = Sheets("Tel-Nexx Data")
    Set wsTNA = Sheets("Tel-Nexx Archive")

    With Application
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
    End With

    With Intersect(wsTNO.UsedRange, wsTNO.Columns("S"))
        .AutoFilter 1, "<>Same"
        With Intersect(.Offset(2).EntireRow, .Parent.Range("B:P"))
            .Copy wsTNA.Cells(Rows.Count, "B").End(xlUp).Offset(1)
            .EntireRow.Delete
        End With
        .AutoFilter
    End With


'Blow away rows that are useless
    lastrow = wsTND.Range("A2").End(xlDown).Row
    wsTND.Range("O1:P1").Copy wsTND.Range("O2:P" & lastrow)
    wsTND.UsedRange.Copy Sheets.Add.Range("A1")

    With Intersect(ActiveSheet.UsedRange, ActiveSheet.Columns("P"))
        ActiveSheet.Range("O:P").Calculate
        .AutoFilter 1, "<>Different"
        .SpecialCells(xlCellTypeVisible).EntireRow.Delete
    End With

    With ActiveSheet
        lastrow = wsTND.Range("A2").End(xlDown).Row
        Intersect(.UsedRange, .Range("A2:M" & lastrow)).Copy wsTNO.Cells(Rows.Count, "B").End(xlUp).Offset(1)
        .Delete
    End With

    With wsTNO
        lastrow = wsTNO.Cells(Rows.Count, "B").End(xlUp).Row
        wsTNO.Range("T1:AD1").Copy
        wsTNO.Range("B3:N" & lastrow).PasteSpecial xlPasteFormats
        lastrow = wsTNO.Cells(Rows.Count, "R").End(xlUp).Row
        fstcell = wsTNO.Cells(Rows.Count, "N").End(xlUp).Row
        wsTNO.Range("AE1:AI1").Copy wsTNO.Range("O" & fstcell & ":S" & lastrow).Offset(1, 0)
    End With

    With Application
        .ScreenUpdating = True
        .DisplayAlerts = True
        .EnableEvents = True
    End With

End Sub

It technically works perfectly till here:

With wsTNO
        lastrow = wsTNO.Cells(Rows.Count, "B").End(xlUp).Row
        wsTNO.Range("T1:AD1").Copy
        wsTNO.Range("B3:N" & lastrow).PasteSpecial xlPasteFormats
        lastrow = wsTNO.Cells(Rows.Count, "R").End(xlUp).Row
        fstcell = wsTNO.Cells(Rows.Count, "N").End(xlUp).Row
        wsTNO.Range("AE1:AI1").Copy wsTNO.Range("O" & fstcell & ":S" & lastrow).Offset(1, 0)
End With

Now technically everything in this part works correctly, but the last line in the code, it pasts everything correctly, then it goes one step beyond. I’d like to know why. If I get rid of the offset it overwrites what is in the cell above in O through S. I need to know the first and last cell, because the data needs to be only written to a specific cell range.

If there is an easier way of doing this it be appreciated if someone could tell me, if not then can someone tell me how to fix this?

Thanks.

Attached is the workbook.

http://dl.dropbox.com/u/3327208/Excel/First%26LastRows.xlsm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:03:34+00:00Added an answer on June 4, 2026 at 9:03 am

    In your 2nd piece of code add + 1 to

     lastrow = wsTNO.Cells(Rows.Count, "R").End(xlUp).Row
    

    So you have

     lastrow = wsTNO.Cells(Rows.Count, "R").End(xlUp).Row + 1
    

    The former gives you row 2, which is your header row. What you want is row 3, the row right after your headers.

    Update: To Show How To Test in Future

    Although the .Select method is typically frowned upon. It can be great for testing / debugging. I ran

    wsTNO.Range("O" & fstcell & ":S" & lastrow).Select
    

    in the immediate window after I set lastrow and fstcell to find the range that was set. Therefore I knew you didn’t want to copy your headers. From there you can figure out what is driving that range to be set and adjust accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey here is my script: Private Sub UpdateThread() Dim AppDir As String = Application.StartupPath()
I found a script on here that will export each worksheet in a file
Here is the script use strict; sub sortF { my $l1 = hex ${@$a}[0];
I have a host with php+mysql and i need to run a script here
For example, my goal is to test the code given here: PHP script that
Here is my script... all I want to do is have it continuously loop!
Here is my script #!/usr/bin/env ruby if __FILE__ == $0 `cd ..` puts `ls`
Here is a script I can't get to work correctly. It's purpose is to
Here's my script with the personal bits scrubbed. import urllib, urllib2, cookielib cj =
Here is my script: <script type=text/javascript> $(document).ready(function () { $(.div_question).toggle(function () { var answer=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.