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 8957297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:57:26+00:00 2026-06-15T14:57:26+00:00

i am attempting to write a script that goes over a specific column and

  • 0

i am attempting to write a script that goes over a specific column and then copies all rows containing the value of “rejected” in said column to a new excel file/workbook.

Everything seems to work just fine except for the actual Paste command which fails every time.

The code:

Sub button()

  Dim x As String
  Dim found As Boolean
  strFileFullName = ThisWorkbook.FullName
  strFileFullName = Replace(strFileFullName, ".xlsm", "")
  strFileFullName = strFileFullName + "_rejected.xlsx"
 ' MsgBox strFileFullName
  Set oExcel = CreateObject("Excel.Application")
  Set obook = oExcel.Workbooks.Add(1)
  Set oSheet = obook.Worksheets(1)
  oSheet.Name = "Results"

  ' Select first line of data.
  Range("E2").Select
  ' Set search variable value.
  x = "rejected"
  ' Set Boolean variable "found" to false.
  found = False
  ' Set Do loop to stop at empty cell.
  Do Until IsEmpty(ActiveCell)
     ' Check active cell for search value.
     If ActiveCell.Value = "" Then
     Exit Do
     End If
     If ActiveCell.Value = x Then
        found = True

        rowToCopy = ActiveCell.Row
        ActiveSheet.Rows(ActiveCell.Row).Select
        Selection.Copy

        oSheet.Range("A1").Select
        lastrow = oSheet.Cells(Rows.Count, "B").End(xlUp).Row
    '   oSheet.Rows(1).Select.PasteSpcial

     End If
     ' Step down 1 row from present location.
     ActiveCell.Offset(1, 0).Select

      Loop
   ' Check for found.
      If found = True Then
         MsgBox "Value found in cell " & ActiveCell.Address
      Else
         MsgBox "Value not found"
      End If
      obook.SaveAs strFileFullName
      obook.Close
End Sub

Any idea why i keep failing with the paste function?

Thanks!

  • 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-15T14:57:27+00:00Added an answer on June 15, 2026 at 2:57 pm

    Try this, no selects involved.

     Sub AddWB()
        Dim nwBk As Workbook, WB As Workbook, Swb As String
        Dim Rws As Long, Rng As Range, c As Range, sh As Worksheet
    
        Set WB = ThisWorkbook
        Set sh = WB.Worksheets("Sheet1")
    
        Rws = sh.Cells(Rows.Count, "E").End(xlUp).Row
        Set Rng = Range(sh.Cells(2, 5), sh.Cells(Rws, 5))
    
        Set nwBk = Workbooks.Add(1)
        Swb = WB.Path & "\" & Mid(WB.Name, 1, Len(WB.Name) - 5) & ".xlsx"
        MsgBox Swb
    
        For Each c In Rng.Cells
            If c = "x" Then c.EntireRow.Copy nwBk.Sheets(1).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        Next c
    
        nwBk.SaveAs Filename:=Swb
    
    End Sub
    

    XLorate.com

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

Sidebar

Related Questions

I'm attempting to write a script that returns rows from a mySQL database. Basically,
I'm attempting to write a particular script that logs into a website. This specific
I am attempting to write a bash script that changes directory and then runs
I have been attempting to write a VBA Script that can parse out other
I am curretnly attempting to write a script in python that allows me to
I am attempting to write a Perl script that parses a log where on
I'm trying to learn jquery, so I'm attempting to write a script that'll hide
I am attempting to write a user script that makes a cross domain AJAX
I am attempting to write a launchd script that runs once a day, on
I'm attempting to write a script that generates a basic Simulink model and I'd

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.