Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy info from master sheet to new worksheet

Status
Not open for further replies.

thomasks

Programmer
May 12, 2006
113
US
Hi all,
A coworker of mine has asked if I could take the data that is on a master worksheet in excel, and enable a way to highlight(select) rows. Then have a dialog box pop up and ask the user what the new worksheet name should be, then copy the selected data to the new sheet. After that has been done he wants the copied data on the master sheet to either change color, or bold or something to show that these rows have already been done. Can anyone point me to code to do this?
Thanks
 
something along the lines of
Code:
Sub FindMeData()
    
    Dim strToFind As String
    Dim newWorkSheetName As String
    Dim startCell As Variant
    Dim cellCount As Integer
    Dim masterSheet As String
    
    cellCount = 0
    'ask for search term'
    strToFind = InputBox("Enter Search Term", "Data Locater")
    masterSheet = ActiveWorkbook.ActiveSheet.Name
    'ask for new sheet name
    newWorkSheetName = InputBox("Enter Name", "Create New Worksheet")
    'Select a start point'
    Range("A1").Select
    'Find Search term within sheet'
    Cells.Find(What:=strToFind, After:=ActiveCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Activate
    'Select next cell down and record start position'
    Selection.Offset(1, 0).Select
    startCell = Selection.Address
    'Look at all the cells until a blank one is found'
    Do
        If (Selection.Value = Empty) Then
            Exit Do
        End If
        If (Selection.Text = "") Then
            Exit Do
        End If
        cellCount = cellCount + 1
        Selection.Offset(1, 0).Select
    Loop
    'Select the range and copy it'
    Range(startCell, Selection.Offset(-1, 0).Address).Select
    Selection.Copy
    'Create Results Sheet'
    ActiveWorkbook.Sheets.Add
    ActiveWorkbook.ActiveSheet.Name = newWorkSheetName
    'copy Selection to new sheet'
    Range("A1").Select
    Range(Selection.Address, Selection.Offset(cellCount - 1, 0).Address).Select
    ActiveSheet.Paste
    ActiveWorkbook.Sheets(masterSheet).Activate
    Selection.Font.ColorIndex = 3
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top