+ Reply to Thread
Results 1 to 2 of 2

What have I done wrong with this Macro???

  1. #1
    Registered User
    Join Date
    08-12-2005
    Posts
    21

    Arrow What have I done wrong with this Macro???

    Hi I have written the following Macro to copy specific data into separate worksheets dependenat on the cell value in columnA.
    It works with copying cellValues of '9' into Sheet'9-10' but then it copies all data with cellValues of '9' or '10' into Sheet'10-11'. In thisa sheet i only want data with cellValue of '10' to be copied.

    Please can you help!!!!!

    Sub STEP3()
    Dim rng As Range, cell As Range, sel As Range
    Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    For Each cell In rng
    If (cell.Value) = "9" Then
    If sel Is Nothing Then
    Set sel = cell
    Else: Set sel = Union(sel, cell)
    End If
    End If
    Next
    On Error Resume Next
    sel.EntireRow.Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("9-10").Select
    Range("A3").Select
    ActiveSheet.Paste

    Sheets("Sheet2").Select
    Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    For Each cell In rng
    If (cell.Value) = "10" Then
    If sel Is Nothing Then
    Set sel = cell
    Else: Set sel = Union(sel, cell)
    End If
    End If
    Next
    On Error Resume Next
    sel.EntireRow.Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("10-11").Select
    Range("A3").Select
    ActiveSheet.Paste
    End Sub

  2. #2
    Jim Cone
    Guest

    Re: What have I done wrong with this Macro???

    S,

    Set sel to nothing before starting on sheet2.

    Jim Cone
    San Francisco, USA


    "Shandy720"
    <Shandy720.1tnmuc_1123855972.6749@excelforum-nospam.com>
    wrote in message
    news:Shandy720.1tnmuc_1123855972.6749@excelforum-nospam.com...Hi I have written the following Macro to copy specific data into
    separate worksheets dependenat on the cell value in columnA.
    It works with copying cellValues of '9' into Sheet'9-10' but then it
    copies all data with cellValues of '9' or '10' into Sheet'10-11'. In
    thisa sheet i only want data with cellValue of '10' to be copied.
    Please can you help!!!!!

    Sub STEP3()
    Dim rng As Range, cell As Range, sel As Range
    Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    For Each cell In rng
    If (cell.Value) = "9" Then
    If sel Is Nothing Then
    Set sel = cell
    Else: Set sel = Union(sel, cell)
    End If
    End If
    Next
    On Error Resume Next
    sel.EntireRow.Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("9-10").Select
    Range("A3").Select
    ActiveSheet.Paste

    Sheets("Sheet2").Select
    Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
    For Each cell In rng
    If (cell.Value) = "10" Then
    If sel Is Nothing Then
    Set sel = cell
    Else: Set sel = Union(sel, cell)
    End If
    End If
    Next
    On Error Resume Next
    sel.EntireRow.Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("10-11").Select
    Range("A3").Select
    ActiveSheet.Paste
    End Sub
    --
    Shandy720


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1