Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Use macro to check a range of cells within a row and copy wanted data to new sheet


I have a problem and am not very familiar with VBA.
What I need to do is check a row of data one at a time (there are abou
3000 total rows) looking for a class number (the class numbers are i
different columns within the row). When I find that class number withi
the row I need to *copy* the row to another sheet. I am simply trying t
grab all of the students in certain classes and paste them on anothe
sheet.

Here is a sample of the data:
Adams gadams21 041184 84022 84260
Adams hadams4 111591 83772
Adams dadams25 041645 84020 84282
Adams madams3 082981 83969
Adams sadams9 120369 81838 84025 86460

The first column is last name (yes, I have changed the data...none o
it is sensitive).
The second column is user name.
3rd column is birthday.
Remaining columns are classes they are in (can vary; some can be in
classes, some in 1).

Any help would be greatly appreciated.

Thanks,

busspee

--
busspee
-----------------------------------------------------------------------
busspeed's Profile: http://www.excelforum.com/member.php...fo&userid=1482
View this thread: http://www.excelforum.com/showthread.php?threadid=26463

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Use macro to check a range of cells within a row and copy wanted data to new sheet

bus,

MACRO

You can use a macro - the macro below will extract all the data for a
particular class code and copy it to a new worksheet.

MANUAL

The manual method that depends on one additional column of formulas. Firts,
though, you will need a single cell for the class code that you want to
extract. Let's use A1 for our example.

Then use a column of formulas - in, let's say, column I, which I'll assume
to be blank: Enter this if cell I2:

=NOT(ISERROR(MATCH($A$1,A2:H2,FALSE)))

and copy that down to match your table.

Then use Data | Filter... Autofilter, and select the TRUE values of column
I. Then select your entire data table, use Edit | Go To... Special Visible
cells, then do your copy and paste to the new sheet.

HTH,
Bernie
MS Excel MVP

Sub FindClassCodeValues()
Dim c As Range ' The cell found with what you want
Dim d As Range ' All the cells found with what you want
Dim myFindString As String
Dim firstAddress As String
Dim mySht As Worksheet

myFindString = InputBox("Enter the class code", , "Hello")
With Cells
Set c = .Find(myFindString, LookIn:=xlValues, lookAt:=xlWhole)

If Not c Is Nothing Then
Set d = c
firstAddress = c.Address
Else:
MsgBox "Not Found"
End
End If

Set c = .FindNext(c)
If Not c Is Nothing And c.Address < firstAddress Then
Do
Set d = Union(d, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
'Then all the rows of the cells that have been found

Set mySht = Worksheets.Add
mySht.Name = "Class " & myFindString
d.EntireRow.Copy mySht.Range("A1")

End Sub



"busspeed" wrote in message
...

I have a problem and am not very familiar with VBA.
What I need to do is check a row of data one at a time (there are about
3000 total rows) looking for a class number (the class numbers are in
different columns within the row). When I find that class number within
the row I need to *copy* the row to another sheet. I am simply trying to
grab all of the students in certain classes and paste them on another
sheet.

Here is a sample of the data:
Adams gadams21 041184 84022 84260
Adams hadams4 111591 83772
Adams dadams25 041645 84020 84282
Adams madams3 082981 83969
Adams sadams9 120369 81838 84025 86460

The first column is last name (yes, I have changed the data...none of
it is sensitive).
The second column is user name.
3rd column is birthday.
Remaining columns are classes they are in (can vary; some can be in 5
classes, some in 1).

Any help would be greatly appreciated.

Thanks,

busspeed


--
busspeed
------------------------------------------------------------------------
busspeed's Profile:

http://www.excelforum.com/member.php...o&userid=14829
View this thread: http://www.excelforum.com/showthread...hreadid=264630



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Use macro to check a range of cells within a row and copy wanted data to new sheet

Sub copyData
Dim rng as Range, lRow as Long
With .Columns("D:J")
set rng = .find(84022)
if not rng is nothing then
lRow = rng.row
do
rng.EntireRow.copy Destination:= _
worksheets("Sheet2").Cells(rows.count,1).End(xlup) (2)
set rng = .FindNext(rng)
Loop while rng.row < lRow
End with

End Sub



"busspeed" wrote in message
...

I have a problem and am not very familiar with VBA.
What I need to do is check a row of data one at a time (there are about
3000 total rows) looking for a class number (the class numbers are in
different columns within the row). When I find that class number within
the row I need to *copy* the row to another sheet. I am simply trying to
grab all of the students in certain classes and paste them on another
sheet.

Here is a sample of the data:
Adams gadams21 041184 84022 84260
Adams hadams4 111591 83772
Adams dadams25 041645 84020 84282
Adams madams3 082981 83969
Adams sadams9 120369 81838 84025 86460

The first column is last name (yes, I have changed the data...none of
it is sensitive).
The second column is user name.
3rd column is birthday.
Remaining columns are classes they are in (can vary; some can be in 5
classes, some in 1).

Any help would be greatly appreciated.

Thanks,

busspeed


--
busspeed
------------------------------------------------------------------------
busspeed's Profile:

http://www.excelforum.com/member.php...o&userid=14829
View this thread: http://www.excelforum.com/showthread...hreadid=264630



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro print range not dynamic like I wanted it to be TRYING Excel Worksheet Functions 8 November 27th 07 01:05 AM
Macro - copy a range and paste it in a new sheet 12 times Eva Excel Worksheet Functions 0 September 26th 07 07:20 PM
help wanted to clean up a data sheet jvoortman Excel Discussion (Misc queries) 9 October 24th 05 03:38 PM
Check box - if ticked copy data from one sheet to another automati rickerscote Excel Discussion (Misc queries) 0 April 14th 05 09:25 AM
Data Validation to check Dynamic range in another sheet Soniya Excel Programming 2 August 12th 03 12:52 PM


All times are GMT +1. The time now is 03:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"