Visual Basic for Applications (VBA)


List Box selection, want to copy all data in the worksheet that matches the selection to another worksheet


I have a list box in a form (VBA).  I am not sure how to write the VBA code that will take the list box selection - compare it to the worksheet data (about 24000 rows) - copy only those rows to another sheet where the selection in the list box matches a cell in the data.
Hi JacksoYou could use this code in the Listbox change event of VBA. Here I assume that Worksheet 2 is the sheet when you are searching for the data that is selected in the listbox and worksheet 3 is the sheet where the selected row is copied. Private Sub ListBox1_Change()Dim rng As Range, cell As RangeDim str As Stringstr = ListBox1.ValueSet rng = ActiveWorkbook.Worksheets(2).UsedRange.CellsFor Each cell In rng    If cell.Value = str Then        cell.EntireRow.Cells.Copy        lastrow = lastrow + 1        Worksheets(3).Paste Destination:=Worksheets(3).Range("A" & lastrow)    End IfNext cellEnd SubLet me know if it helps! Please vote as helpful if this works for you.

Related Links

How to Allocate Input Numeric digit to Concerned Numeric header Column
Range referencing in Copy and Paste Formats
VBA6 trouble in WINDOWS 10
VBA dynamic formula reference
Printing Userform
Sorting and selecting cells based off name.
How to tune auto filter option for our need???
VBA Loggin into secure websites
MS Project import of custom field data from Excel resulting in Run-time error 462
How to write a filtered data as a text file using macros???
Block specific site and show custom content?
Need Urgent Help, Plzzzzzz what code add in vba to display a html web link, it should be display in outlook body. not a link should be display as we open in explorer
Activate PowerPoint and add slide Vba
Any way to use an Access application in batch mode (no UI)?
VBA Code for below requirement...
Help with exporting Content From Outlook 2010 Emails To Excel Spreadsheet

Categories

MSDN
Windows Phone Development
Windows Phone Dev Center
BizTalk Server
DevLabs
HealthVault
Microsoft Sync Framework
Orchard
In-App Advertising (Ad...
Archived Forums
Maps In Windows
Virtualization
Cortana
Announcements for all ...
Off-Topic Posts (Do No...
Visual C#
Visual Studio Code Vis...
Visual Studio Diagnost...
Application Insights (AI)
Register and Manage Ac...
AdSDK Integration & Ad...
Windows Desktop Develo...
DirectShow Development
Network Monitor
Outlook for Developers
Office 365 for Developers
SharePoint 2013 - Usin...
SharePoint Legacy Vers...
Pricing & Billing
Azure Media Services
Azure Automation
StorSimple
Azure App Service - AP...
Azure DevTest Labs
Azure Analysis Services
Azure Time Series Insi...
Windows Presentation F...
Claims based access pl...
Team Foundation Server...
Team Foundation Server...
Visual FoxPro General
BizTalk ESB Toolkit
WCF Data Services
Debugger Canvas
Microsoft Live Labs Volta
Microsoft Translator U...
SyncFx - General [Read...
SyncFx - Microsoft Syn...
Microsoft Robotics - V...
SQL Server Database En...
Microsoft Drivers for ...
SQL Server Spatial
Power Pivot
SQL Server PowerPivot ...
Windows Embedded 8.1 I...
Windows Embedded Compa...
SQL Server 2012 PowerP...
CRM Deployment
WebsitePanel - Discuss...
Microsoft Automatic Gr...
Bing Maps General
Project Server - Setup...
Microsoft Lync Persist...
Programming Silverligh...
Silverlight Controls a...
Game Development with ...
Expression Blend + Ske...
Expression Studio
Reference Source Serve...
Visual Studio Report C...
Casablanca
Expression Community S...
Game Technologies: XNA...
General Windows MultiP...
Installing and Registe...
Microsoft adCenter: De...
Microsoft ESP Platform...
Microsoft "Data Explor...
Office Live Small Busi...
Popfly Bugs and Sugges...
Silverlight (formerly ...
Software Transactional...
SQL Server 2014 Self-S...
SQL Server 2014 Setup ...
Tools for Windows Stor...
UI Design for Windows ...
Visual Basic Interop a...
Visual C# Express 2008...
Visual Studio Lab Mana...
Visual Studio Team Sys...
Visual Studio UI Autom...
Web Sandbox - Exploits
Tools for Windows Stor...
Expression Blend for W...
Windows Phone Preview ...
Skype Web SDK

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile