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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:38:55+00:00 2026-06-04T05:38:55+00:00

I would like to copy the Name and Description If Quantity on and is

  • 0

I would like to copy the Name and Description If Quantity on and is equal to zero so I can order the fruit that I do not have. It starts from A2 whenever it see “STOP” then it stops.

enter image description here

I have the code:
enter image description here

However, the code does not stop by itself, I have to break it when it runs. It copies all empty rows between and entire row when I only need to have first 2 columns. My questions are 1. how to let the program knows it should stop when see “STOP” at column A? Only copy none empty row? and only copy first two column (or the number of columns that I would like to have)?

  • 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-04T05:38:56+00:00Added an answer on June 4, 2026 at 5:38 am
    1. Stop the loop
      The problem is in your While clause: you are comparing the length of a string to a string – that will never be TRUE

    2. Copy only non-empty rows
      Test for valid data

    3. Copy required number of columns
      See sample code

    FWIW your code can do with a bit of improving – heres my take on your requirements

    Sub CopySample()
        Dim shSrc As Worksheet
        Dim shDst As Worksheet
        Dim rSrc As Range
        Dim rDst As Range
        Dim numCol As Long ' number of columns to copy
    
        On Error GoTo EH
    
        numCol = 2
    
        ' select source and dest sheets
        Set shSrc = ActiveWorkbook.Worksheets("Sheet1")
        Set shDst = ActiveWorkbook.Worksheets("Sheet2")
    
        ' Select initial rows
        Set rSrc = shSrc.Cells(2, 1)
        Set rDst = shDst.Cells(23, 1)
    
        ' loop over source
        Do While rSrc <> "STOP"
            ' Test Source row, Qty = 0 and Name is not blank
            With rSrc
                If .Offset(0, 2) = 0 And .Value <> "" Then
                    'Copy
                    .Resize(1, numCol).Copy rDst.Resize(1, numCol)
                    Set rDst = rDst.Offset(1, 0)
                End If
            End With
            Set rSrc = rSrc.Offset(1, 0)
        Loop
    Exit Sub
    EH:
        MsgBox "Error " & Err.Description
    End Sub
    

    Note that looping over a range can be slow for large amounts of data. Probably OK in this case, but there are ways to improve speed.

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

Sidebar

Related Questions

I have a Visual Studio 2008 C++ project where I would like to copy
I have git repositories rA and rB, I would like to copy only specific
I would like to include a Copy method on a runtime built type that
I would like to know how I can access the copy of my sqlite
Alright I have a gigantic list of files I would like to copy from
I have an existing project in AppCode that I would like to use as
I would like copy just file.xml without folder structure using overlays like this: <overlays>
I would like to copy stdout and stderr of my Perl script to a
I would like to copy an array of pixel data (colors) into a texture.
I would like to copy to clipboard what a Control of my WPF app

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.