Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2014, 03:00 AM
funkyfido funkyfido is offline Macro help Windows XP Macro help Office 2007
Novice
Macro help
 
Join Date: Jun 2013
Posts: 24
funkyfido is on a distinguished road
Default Macro help

I have a large spreadsheet where all the data comes out in the one go. I want to do the following:-



Find CY and copy all the data (columns A-L) up to DL but not including DL and put it on a new sheet named CY
Find DL and copy all the data up to EU but not including EU and put it on a new sheet named CY
Find EU and copy remaing data into a new sheet named EU.

How would I do this? I am fairly new to macros so any help would be appreciated. I have attached a test copy of my data.
Attached Files
File Type: xlsx Test file.xlsx (430.7 KB, 9 views)
Reply With Quote
  #2  
Old 05-27-2014, 10:12 PM
macropod's Avatar
macropod macropod is offline Macro help Windows 7 32bit Macro help Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim lRow As Long, lCol As Long, i As Long, j As Long
Dim xlWkBk As Workbook, xlSht As Worksheet, StrSht As String
Set xlWkBk = ThisWorkbook: StrSht = ""
Set xlSht = xlWkBk.Worksheets("Sheet1")
With xlWkBk.Worksheets("Sheet1").UsedRange
  lRow = .Range("A" & .Cells.SpecialCells(xlCellTypeLastCell).Row).End(xlUp).Row
  lCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
  For i = 1 To lRow
    Select Case .Cells(i, 1).Text
      Case "CY"
        StrSht = "CY": j = 0
        Set xlSht = xlWkBk.Sheets.Add(After:=xlSht)
        xlSht.Name = StrSht
      Case "DL"
        StrSht = "DL": j = 0
        Set xlSht = xlWkBk.Sheets.Add(After:=xlSht)
        xlSht.Name = StrSht
      Case "EU"
        StrSht = "EU": j = 0
        Set xlSht = xlWkBk.Sheets.Add(After:=xlSht)
        xlSht.Name = StrSht
    End Select
    If StrSht <> "" Then
      j = j + 1
      .Range(.Cells(i, 1), .Cells(i, lCol)).Copy
      xlSht.Paste Destination:=xlSht.Cells(j, 1)
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-30-2014, 03:22 AM
funkyfido funkyfido is offline Macro help Windows XP Macro help Office 2007
Novice
Macro help
 
Join Date: Jun 2013
Posts: 24
funkyfido is on a distinguished road
Default

This gave me some errors but I managed another workaround
Reply With Quote
  #4  
Old 05-30-2014, 03:54 AM
macropod's Avatar
macropod macropod is offline Macro help Windows 7 32bit Macro help Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Unless your data and/or the worksheet itself are different to what you posted, I can't see how that's possible. The macro was coded, tested and confirmed as working correctly with the worksheet you posted.

Finally, merely saying "This gave me some errors" without saying what they were robs yourself of any chance of getting the problem solved, so all you're left with is a 'workaround'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
macro



Similar Threads
Thread Thread Starter Forum Replies Last Post
custom icon, undo/redo for macro, permanent macro Rapier Excel 0 08-05-2013 06:30 AM
How do I assign a macro to a button when the macro is in my personal workbook? foolios Excel Programming 2 07-27-2011 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft