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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:30:10+00:00 2026-05-25T12:30:10+00:00

Sub Test3() Dim LSearchRow As Integer Dim LCopyToRow As Integer On Error GoTo Err_Execute

  • 0
Sub Test3()

Dim LSearchRow As Integer
Dim LCopyToRow As Integer

On Error GoTo Err_Execute

'Start search in row 5
LSearchRow = 5

'Start copying data to row 2 in Sheet3 (row counter variable)
LCopyToRow = 2

While Len(Range("Y" & CStr(LSearchRow)).Value) > 0

    'If value in column Y = "84312570", copy entire row to Sheet3
    If Range("Y" & CStr(LSearchRow)).Value = "84312570" Then

        'Select row in MasterList to copy
        Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
        Selection.Copy

        'Paste row into Sheet3 in next row
        Sheets("Sheet3").Select
        Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
        ActiveSheet.Paste

        'Move counter to next row
        LCopyToRow = LCopyToRow + 1

        'Go back to MasterList to continue searching
        Sheets("MasterList").Select

    End If

    LSearchRow = LSearchRow + 1

Wend

'Position on cell A5
Application.CutCopyMode = False
Range("A5").Select

MsgBox "All matching data has been copied."

Exit Sub

Err_Execute:
    MsgBox "An error occurred."

End Sub

This finds specific values in Column Y and moves entire rows of corresponding information to individual worksheets.

I have two questions.

First, is there a way to specify only certain columns of information be moved to the individual sheets instead of moving the entire row?

Second, is there a way to pull information based off of only the last 4 digits of the number sequence in column Y? For example, above I would want to pull all rows whose number in column Y matched *2570.

  • 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-25T12:30:11+00:00Added an answer on May 25, 2026 at 12:30 pm

    Untested: edit arrColsToCopy to include the columns you want copied over

    Sub Test3()
    
        Dim LCopyToRow As Long
        Dim LCopyToCol As Long
        Dim arrColsToCopy
        Dim c As Range, x As Integer
    
        On Error GoTo Err_Execute
    
    
        arrColsToCopy = Array(1, 2, 3, 5, 10, 15) 'which columns to copy ?
        Set c = Sheets("MasterList").Range("Y5") 'Start search in row 5
        LCopyToRow = 2  'Start copying data to row 2 in Sheet3
    
        While Len(c.Value) > 0
    
            'If value in column Y ends with "2570", copy to Sheet3
            If c.Value Like "*2570" Then
    
                LCopyToCol = 1
                For x = LBound(arrColsToCopy) To UBound(arrColsToCopy)
    
                     Sheets("Sheet3").Cells(LCopyToRow, LCopyToCol).Value = _
                                    c.EntireRow.Cells(arrColsToCopy(x)).Value
    
                    LCopyToCol = LCopyToCol + 1
    
                Next x
    
                LCopyToRow = LCopyToRow + 1 'next row
    
            End If
    
            Set c = c.Offset(1, 0)
    
        Wend
    
        'Position on cell A5
        Range("A5").Select
    
        MsgBox "All matching data has been copied."
    
        Exit Sub
    
    Err_Execute:
            MsgBox "An error occurred."
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imports System.Data.SqlClient Module Module1 Sub Main() Dim iCount As Integer = 1 Try Do
I get the compile-time error User-defined types not defined on this line: Dim cn
Here's a short test program: sub foo($;@) { my $sql = shift; my @params
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()
How to move a sub directory from one directory to another, given that both
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
A python script need to spawn multiple sub-processes via fork(). All of those child
How do I copy a directory including sub directories excluding files or directories that

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.