Avatar of Billa7
Billa7

asked on 

Copy data from sheet 1 to sheet 2

Hi,

Need Experts help create a macro to copy data from Column A: G at sheet 1 to sheet 2 if data at column A has “02”, e.g. data at cell A5 with “02”, therefore the whole row (A:G) need to copy at sheet 2. Hope Experts could help me create this feature. I have manually copied few data at sheet2 for experts to get a better view.
Filter-Data.xlsx
Microsoft Excel

Avatar of undefined
Last Comment
Steve
ASKER CERTIFIED SOLUTION
Avatar of Steve
Steve
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Billa7
Billa7

ASKER

Hi,

Thanks a lot for the help
Avatar of Steve
Steve
Flag of United Kingdom of Great Britain and Northern Ireland image

OK, didn't like my original code above.
(would handle each cell value individualy if was going to validate or change values)

Here is code which is a little better for each file:
Sub FilterSheets()

Dim DataWs As Worksheet
Dim NewWs As Worksheet
Set DataWs = Sheets("Sheet1")
Set NewWs = Sheets("Sheet2")

NumRows = DataWs.UsedRange.Rows.Count
For x = 2 To NumRows
Code = DataWs.Cells(x, 1)
If Code Like "*02*" Then
    NewWsRows = NewWs.UsedRange.Rows.Count + 1
    DataWs.Rows(x).Copy NewWs.Rows(NewWsRows)
End If

Next
End Sub

Open in new window


It just bugs me if I know I can get the job done with a little less code :)
Filter-Data.xlsm
Filter-Data-All.xlsm
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo