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

  • SEARCH
  • Home
  • 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 6390377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:32:29+00:00 2026-05-25T03:32:29+00:00

So I want a macro running in an Excel file (input.xls) that is searching

  • 0

So I want a macro running in an Excel file (“input.xls”) that is searching a column in another Excel file (“data.xls”) for the value “1” (the only values in that columns are 1s and 0s). When it finds a “1,” it should copy and paste the entire row from that file into “input.xls”.

Here is the code that I have

Sub NonErrorDataParse()
    Dim intEnd As Integer

    Workbooks("data.xls").Sheets("Raw").Activate

    intEnd = 65000

    Range("F").Select

    Do Until ActiveCell.Row = intEnd

        If Int(ActiveCell.Value) = 1 Then
            Range(ActiveCell.Row & ":" & ActiveCell.Row).Cut
            intEnd = intEnd - 1
            Workbooks("input.xls").Sheets("Non-errors").Activate
            Range("A1").Select
            ActiveSheet.Paste
        Else
            ActiveCell.Offset(1, 0).Select
        End If

    Loop

End Sub

However, when I run it, it gives me a “subscript out of range” error on “data.xls.” No matter how I fiddle with the code I can’t seem to get past that error (even though I have OTHER macros that are accessing that sheet that work fine).

Any ideas as to how to fix it? Or better code that will do the same thing?

Thanks in advance

  • 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-05-25T03:32:30+00:00Added an answer on May 25, 2026 at 3:32 am

    You don’t have to Select or Activate each time you do a command.
    You can also find the last used cell with Range("A65536").End(xlup) instead of parsing every cell (that probably caused your error).

    The code would then look like:

    Sub NonErrorDataParse()
        Dim intEnd As Integer
        Dim c As Range
    
        intEnd = Workbooks("data.xls").Sheets("Raw").Range("A65536").End(xlUp).Row
    
        For Each c In Workbooks("data.xls").Sheets("Raw").Range("F1:F" & intEnd)
           If CStr(c.Value) = "1" Then
               c.EntireRow.Cut
               Workbooks("input.xls").Sheets("Non-errors").Rows("1:1").Insert Shift:=xlDown
           End If
        Next c
    End Sub
    

    Yet, if you have many rows, it would be faster to use the autofilter method or use a dictionary.

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

Sidebar

Related Questions

I want a debug function-macro that works like this: int myVar = 5; PRINTVAR(myVar);
I want to create a C macro that creates a function with a name
I want to connect to DB2 from excel macro...This is my code, but it
I want to add a subroutine into my Word 2007 macro that will take
I have an access macro, that I want to run automatically from a batch
I have CSV file and Macro in VBA. I want to open CSV file
I am trying to display milliseconds in an Excel macro. I have a column
in ms-access i am running a macro that runs several queries, during the execution
I want to drop a # temp table when running then macro, is it
I'm running a macro that interacts with an API to pull in information about

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.