• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

When run this macro it delete all data.

febausa

Member
I used this macro for many months with no problem; I delete all data I reinsert new data then when I run the macro it delete all data reinsert before.

Please, help me in fix the problem with macro.

Next, show the macro.
Code:
Sub BallSet()

  max_tabs = Worksheets.Count
  For Tabs = 2 To max_tabs
  With Sheets(Tabs)
  y_max = .Cells(Rows.Count, 1).End(xlUp).Row
  If y_max > 1 Then
  .Activate
  .Range("A2:H" & y_max).ClearContents
  End If
  End With
  Next Tabs
  
  With Sheets("data")
  .Select
  y_max = .Cells(Rows.Count, 1).End(xlUp).Row
  
  For y = 3 To y_max Step 2
  Acol = .Cells(y, 1)
  If IsDate(Acol) Then
  Bcol = .Cells(y, 2)
  Ccol = .Cells(y, 3)
  On Error Resume Next
  Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)
  If Err.Number = 0 Then
  Ntab = Ntab + 1
  With Worksheets(Ntab)
  yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1
  If yy < 1 Then yy = 2
  .Cells(yy, 1) = Acol
  .Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"
  .Cells(yy, 2) = Bcol
  For x = 3 To 8
  .Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)
  Next x
  End With
  End If
  End If
  Next y
  End With
  ans = MsgBox("Ready")
End Sub


Sub OLD_BallSet()
  Application.ScreenUpdating = False
  
  Sheets("Data").Activate
  Sheets("Data").Columns("J:L").ClearContents
  max_tabs = Worksheets.Count
  y = 1
  For Tabs = 2 To max_tabs
  yy = 2
  Do
  If Sheets(Tabs).Cells(yy, 1) <> Empty Then
  For x = 1 To 3
  Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)
  Next x
  y = y + 1
  End If
  yy = yy + 1
  Loop Until Sheets(Tabs).Cells(yy, 1) = Empty
  Next Tabs
  
  Sheets("data").Sort.SortFields.Clear
  Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With Sheets("data").Sort
  .SetRange Range("J1:L" & y - 1)
  .Header = xlNo
  .MatchCase = False
  .Orientation = xlTopToBottom
  .SortMethod = xlPinYin
  .Apply
  End With
  
  With Sheets("data")
  prev_year = -1
  y = 1
  yy = 1
  If .Cells(yy, 10) = Empty Then Exit Sub
  With .Columns("A:H")
  .ClearContents
  .UnMerge
  .Interior.ColorIndex = xlNone
  With .Font
  .Underline = xlNone
  .Bold = True
  .Size = 7
  End With
  .HorizontalAlignment = xlCenter
  .VerticalAlignment = xlCenter
  End With
  Do
  If Year(.Cells(yy, 10)) <> prev_year Then
  .Cells(y, 1) = "Date"
  .Cells(y, 2) = "Ballset"
  .Cells(y, 3) = "Numbersdrawn"
  .Cells(y + 1, 1) = "year"
  .Cells(y + 1, 2) = Year(.Cells(yy, 10))
  .Range(.Cells(y, 3), .Cells(y, 8)).Merge
  With .Range(.Cells(y, 1), .Cells(y + 1, 8))
  .Interior.ColorIndex = 6
  .Font.Underline = xlUnderlineStyleSingle
  End With
  prev_year = .Cells(y + 1, 2)
  y = y + 2
  End If
  .Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")
  .Cells(y, 1).NumberFormat = "@"
  .Cells(y, 2) = .Cells(yy, 11)
  For x = 3 To 8
  .Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)
  .Cells(y, x).NumberFormat = "00"
  Next x
  .Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")
  .Cells(y + 1, 1).NumberFormat = "@"
  y = y + 2
  yy = yy + 1
  Loop Until .Cells(yy, 10) = Empty
  
  .Columns("J:L").ClearContents
  .Range("I3").Select
  End With
  
End Sub
 
Last edited by a moderator:
As Tip:
  • Use [ CODE ] & [ /CODE ] tags to embed your VBA Macros
  • Upload a Sample File to get a quicker response
 
Everything highlighted in the comments is clearing data from a sheet or range. Check

to make certain those areas you want to be cleared :

Code:
Sub BallSet()


  max_tabs = Worksheets.Count

For Tabs = 2 To max_tabs

With Sheets(Tabs)

  y_max = .Cells(Rows.Count, 1).End(xlUp).Row

If y_max > 1 Then

  .Activate

.Range("A2:H" & y_max).ClearContents     ' <----------------------------

End If

End With

Next Tabs


With Sheets("data")

  .Select

  y_max = .Cells(Rows.Count, 1).End(xlUp).Row


For y = 3 To y_max Step 2

  Acol = .Cells(y, 1)

If IsDate(Acol) Then

  Bcol = .Cells(y, 2)

  Ccol = .Cells(y, 3)

On Error Resume Next

  Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)

If Err.Number = 0 Then

  Ntab = Ntab + 1


With Worksheets(Ntab)

  yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1

If yy < 1 Then yy = 2

  .Cells(yy, 1) = Acol

  .Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"

  .Cells(yy, 2) = Bcol


For x = 3 To 8

  .Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)

Next x

End With

End If

End If

Next y

End With

  ans = MsgBox("Ready")

End Sub



Sub OLD_BallSet()

  Application.ScreenUpdating = False


  Sheets("Data").Activate

  Sheets("Data").Columns("J:L").ClearContents       ' <----------------------------

  max_tabs = Worksheets.Count

  y = 1

For Tabs = 2 To max_tabs

  yy = 2

Do

If Sheets(Tabs).Cells(yy, 1) <> Empty Then

For x = 1 To 3

  Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)

Next x

y = y + 1

End If

  yy = yy + 1

Loop Until Sheets(Tabs).Cells(yy, 1) = Empty

Next Tabs


  Sheets("data").Sort.SortFields.Clear

  Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With Sheets("data").Sort

  .SetRange Range("J1:L" & y - 1)

  .Header = xlNo

  .MatchCase = False

  .Orientation = xlTopToBottom

  .SortMethod = xlPinYin

  .Apply

End With


With Sheets("data")

  prev_year = -1

  y = 1

  yy = 1


If .Cells(yy, 10) = Empty Then Exit Sub

With .Columns("A:H")

  .ClearContents      ' <----------------------------

  .UnMerge

  .Interior.ColorIndex = xlNone


With .Font

  .Underline = xlNone

  .Bold = True

  .Size = 7

End With

   = xlCenter

End With

Do

If Year(.Cells(yy, 10)) <> prev_year Then

  .Cells(y, 1) = "Date"

  .Cells(y, 2) = "Ballset"

  .Cells(y, 3) = "Numbersdrawn"

  .Cells(y + 1, 1) = "year"

  .Cells(y + 1, 2) = Year(.Cells(yy, 10))

  .Range(.Cells(y, 3), .Cells(y, 8)).Merge

With .Range(.Cells(y, 1), .Cells(y + 1, 8))

  .Interior.ColorIndex = 6

  .Font.Underline = xlUnderlineStyleSingle

End With

  prev_year = .Cells(y + 1, 2)

  y = y + 2

End If

  .Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")

  .Cells(y, 1).NumberFormat = "@"

  .Cells(y, 2) = .Cells(yy, 11)

For x = 3 To 8

  .Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)

  .Cells(y, x).NumberFormat = "00"

Next x

  .Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")

  .Cells(y + 1, 1).NumberFormat = "@"

  y = y + 2

  yy = yy + 1


  .Columns("J:L").ClearContents           ' <----------------------------

  .Range("I3").Select

End With


Loop Until .Cells(yy, 10) = Empty



End Sub
 
Last edited by a moderator:
Hi, Logit!

Unable to read what vletm posted?

Not just anymore a newbie at these forums, almost 70 posts, so why not use the proper window to post code as to keep it indented and readable? Penultimate icon of the toolbar. Thank you.

Regards!
 
When I posted it wouldn't aaccept
Code:
. Tried several times. Server had a mind of its own.

If I could get to an edit screen now, I would change it.

Thanks. Regards.
 
Test...
Code:
Sub BallSet()


max_tabs = Worksheets.Count

For Tabs = 2 To max_tabs

With Sheets(Tabs)

y_max = .Cells(Rows.Count, 1).End(xlUp).Row

If y_max > 1 Then

.Activate

.Range("A2:H" & y_max).ClearContents

EndIf

EndWith

Next Tabs


With Sheets("data")

.Select

y_max = .Cells(Rows.Count, 1).End(xlUp).Row


For y = 3 To y_max Step 2

Acol = .Cells(y, 1)

If IsDate(Acol) Then

Bcol = .Cells(y, 2)

Ccol = .Cells(y, 3)

OnErrorResumeNext

Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)

If Err.Number = 0 Then

Ntab = Ntab + 1


With Worksheets(Ntab)

yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1

If yy < 1 Then yy = 2

.Cells(yy, 1) = Acol

.Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"

.Cells(yy, 2) = Bcol


For x = 3 To 8

.Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)

Next x

EndWith

EndIf

EndIf

Next y

EndWith

ans = MsgBox("Ready")

EndSub



Sub OLD_BallSet()

Application.ScreenUpdating = False


Sheets("Data").Activate

Sheets("Data").Columns("J:L").ClearContents

max_tabs = Worksheets.Count

y = 1

For Tabs = 2 To max_tabs

yy = 2

Do

If Sheets(Tabs).Cells(yy, 1) <> EmptyThen

For x = 1 To 3

Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)

Next x

y = y + 1

EndIf

yy = yy + 1

LoopUntil Sheets(Tabs).Cells(yy, 1) = Empty

Next Tabs


Sheets("data").Sort.SortFields.Clear

Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With Sheets("data").Sort

.SetRange Range("J1:L" & y - 1)

.Header = xlNo

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

EndWith


With Sheets("data")

prev_year = -1

y = 1

yy = 1


If .Cells(yy, 10) = Empty Then ExitSub

With .Columns("A:H")

.ClearContents

.UnMerge

.Interior.ColorIndex = xlNone


With .Font

.Underline = xlNone

.Bold = True

.Size = 7

EndWith

= xlCenter

EndWith

Do

If Year(.Cells(yy, 10)) <> prev_year Then

.Cells(y, 1) = "Date"

.Cells(y, 2) = "Ballset"

.Cells(y, 3) = "Numbersdrawn"

.Cells(y + 1, 1) = "year"

.Cells(y + 1, 2) = Year(.Cells(yy, 10))

.Range(.Cells(y, 3), .Cells(y, 8)).Merge

With .Range(.Cells(y, 1), .Cells(y + 1, 8))

.Interior.ColorIndex = 6

.Font.Underline = xlUnderlineStyleSingle

EndWith

prev_year = .Cells(y + 1, 2)

y = y + 2

EndIf

.Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")

.Cells(y, 1).NumberFormat = "@"

.Cells(y, 2) = .Cells(yy, 11)

For x = 3 To 8

.Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)

.Cells(y, x).NumberFormat = "00"

Next x

.Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")

.Cells(y + 1, 1).NumberFormat = "@"

y = y + 2

yy = yy + 1


.Columns("J:L").ClearContents

.Range("I3").Select

EndWith


LoopUntil .Cells(yy, 10) = Empty



EndSub

... user comments rejected.
 
SirJB7

I am pleased the server works for you now. At the time I posted it did not. We all know computer systems are not infallible.

I don't appreciate being called a liar. Your last post indicates such.

Since the server is working as intended now, give me access to edit my original post and I'll change it.

Otherwise, stop flexing your muscles. This is not a contest.

Thank you.
 
Hi, Logit!
Please read the written words, I'm responsible for the English interpretation of them, not for your's.
You said the Chandoo server didn't work, a priori I had no opinion about it, I tried what you couldn't, it worked. Then, a posteriori, I posted my opinion about the issue based on the recent test.
Nothing else to add.
Regards!
 
I don't have to read the rules AGAIN. I am aware of what they say. For you [vletm] to jump into this misguided abuse of so called authority is insulting and appalling.

Here are all of my posts to date that include the use of CODE tags:

http://forum.chandoo.org/threads/run-time-error-457.34825/#post-207926
http://forum.chandoo.org/threads/code-for-outlook-mail-with-body.34783/#post-207684
http://forum.chandoo.org/threads/outlook-mail-with-multiple-attachments.34667/#post-207047
http://forum.chandoo.org/threads/how-to-create-a-customized-report-on-my-excel.34347/#post-204805
http://forum.chandoo.org/threads/excel-2003-password-protection.34191/#post-203686
http://forum.chandoo.org/threads/ho...rently-login-in-the-system.34193/#post-203683
http://forum.chandoo.org/threads/ho...older-drive-not-in-outlook.34123/#post-203314
http://forum.chandoo.org/threads/ou...-body-as-html-table-format.34070/#post-203026
http://forum.chandoo.org/threads/how-can-i-refer-to-file-saved-on-desktop-in-code.34038/#post-203017
http://forum.chandoo.org/threads/vba-to-send-pdfs-via-outlook-not-working.34030/#post-202681
http://forum.chandoo.org/threads/how-can-i-refer-to-file-saved-on-desktop-in-code.34038/#post-202609
http://forum.chandoo.org/threads/need-an-help-to-send-an-email-using-vba.33845/#post-201719

None of my other 70 odd posts needed CODE tags.

I know the rules and follow them.

I will not remain silent while some overbearing, insolent, wanna be calls me a liar. SirJB7 jumped to conclusions, did not follow through on his "responsibility" of monitoring the Forum and then proceeded to insult and demean a guest with a tone of superior indifference and supremacy.

Every forum has someone like SirJB7. And it is so sad. Rather than promote the forum and assist - which is what they are assigned to do - they assume, judge and prosecute. Judge, jury and executioner.

The usual excuse is : "Well, we don't get paid to do this you know." Here's a thought for you : None of us get paid to help those seeking assistance. Like you, we are here out of the goodness of our hearts and for the same reason - to assist.

So how about a ton of assistance on your part and his apology to me ?
 
Logit
Okay - no need to read!
.. then try to check how do this (Logit .. SirJB7) begins ...
I wrote #2 Reply
You wrote #3 Reply
SirJB7 wrote #4 Reply
... and after that
... 'bang!' ... 'bang!' ... 'bang!' ...

But the main thing of this discussion should be:
When run this macro it delete all data.

Would You try to write straight to SirJB7 > Conversation > not here?
Anyway,
I would like to help febausa with this discussion ... after a sample file.
 
Can everybody please calm down !!!

When posting or responding to posts

1. Please remember that a lot of non-english people post here and hence their wording or responses may not always be what would be classed as clean or pure English. Please learn to recognise this and not respond in the negative. Add assistance so that they learn and not feel belittled

2. Please remember that people use different versions of Excel in many languages. I cannot be certain that all languages use a ' as a Comment.
The use of [ code ] etc to denote Code assume that a ' is used to denote comments
 
Chandoo.org has been hosted on an extremely reliable system for a number of years now. It is rare but not unkown that issues occur when posting.
The software and servers all need updating from time to time and even things like DNS servers can falter. Patience is generally a great virtue here

As with all things computer related, generally restarting your own system will sort out most issues.
 
Hui:

1. Please remember that a lot of non-english people post here and hence their wording or responses may not always be what would be classed as clean or pure English. Please learn to recognise this and not respond in the negative. Add assistance so that they learn and not feel belittled

I took the time to review previous posts of the participants (a habit SirJB7 should practice) before responding.

All participants have an excellent command of the English language. I recognize that paragraph in your response is probably 'canned' and perhaps you did not really mean to make excuses for someone else's rudeness.

Thank you for looking into this issue.
 
Test...
Code:
Sub BallSet()


max_tabs = Worksheets.Count

For Tabs = 2 To max_tabs

With Sheets(Tabs)

y_max = .Cells(Rows.Count, 1).End(xlUp).Row

If y_max > 1 Then

.Activate

.Range("A2:H" & y_max).ClearContents

EndIf

EndWith

Next Tabs


With Sheets("data")

.Select

y_max = .Cells(Rows.Count, 1).End(xlUp).Row


For y = 3 To y_max Step 2

Acol = .Cells(y, 1)

If IsDate(Acol) Then

Bcol = .Cells(y, 2)

Ccol = .Cells(y, 3)

OnErrorResumeNext

Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)

If Err.Number = 0 Then

Ntab = Ntab + 1


With Worksheets(Ntab)

yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1

If yy < 1 Then yy = 2

.Cells(yy, 1) = Acol

.Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"

.Cells(yy, 2) = Bcol


For x = 3 To 8

.Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)

Next x

EndWith

EndIf

EndIf

Next y

EndWith

ans = MsgBox("Ready")

EndSub



Sub OLD_BallSet()

Application.ScreenUpdating = False


Sheets("Data").Activate

Sheets("Data").Columns("J:L").ClearContents

max_tabs = Worksheets.Count

y = 1

For Tabs = 2 To max_tabs

yy = 2

Do

If Sheets(Tabs).Cells(yy, 1) <> EmptyThen

For x = 1 To 3

Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)

Next x

y = y + 1

EndIf

yy = yy + 1

LoopUntil Sheets(Tabs).Cells(yy, 1) = Empty

Next Tabs


Sheets("data").Sort.SortFields.Clear

Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With Sheets("data").Sort

.SetRange Range("J1:L" & y - 1)

.Header = xlNo

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

EndWith


With Sheets("data")

prev_year = -1

y = 1

yy = 1


If .Cells(yy, 10) = Empty Then ExitSub

With .Columns("A:H")

.ClearContents

.UnMerge

.Interior.ColorIndex = xlNone


With .Font

.Underline = xlNone

.Bold = True

.Size = 7

EndWith

= xlCenter

EndWith

Do

If Year(.Cells(yy, 10)) <> prev_year Then

.Cells(y, 1) = "Date"

.Cells(y, 2) = "Ballset"

.Cells(y, 3) = "Numbersdrawn"

.Cells(y + 1, 1) = "year"

.Cells(y + 1, 2) = Year(.Cells(yy, 10))

.Range(.Cells(y, 3), .Cells(y, 8)).Merge

With .Range(.Cells(y, 1), .Cells(y + 1, 8))

.Interior.ColorIndex = 6

.Font.Underline = xlUnderlineStyleSingle

EndWith

prev_year = .Cells(y + 1, 2)

y = y + 2

EndIf

.Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")

.Cells(y, 1).NumberFormat = "@"

.Cells(y, 2) = .Cells(yy, 11)

For x = 3 To 8

.Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)

.Cells(y, x).NumberFormat = "00"

Next x

.Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")

.Cells(y + 1, 1).NumberFormat = "@"

y = y + 2

yy = yy + 1


.Columns("J:L").ClearContents

.Range("I3").Select

EndWith


LoopUntil .Cells(yy, 10) = Empty



EndSub

... user comments rejected.

Hi SirJB7:

I test your Macro proposal, but no working .Excel wrote in line

EndWith (compile error:Sub or Function no defined)

Thanks for your time.

Febausa
 
Hi ,

All you need to do is separate the keywords :
Code:
Sub BallSet()
    max_tabs = Worksheets.Count
    For Tabs = 2 To max_tabs
        With Sheets(Tabs)
            y_max = .Cells(Rows.Count, 1).End(xlUp).Row
            If y_max > 1 Then
                .Activate
                .Range("A2:H" & y_max).ClearContents
            End If
        End With
    Next Tabs

    With Sheets("data")
        .Select
        y_max = .Cells(Rows.Count, 1).End(xlUp).Row
        For y = 3 To y_max Step 2
            Acol = .Cells(y, 1)
            If IsDate(Acol) Then
                Bcol = .Cells(y, 2)
                Ccol = .Cells(y, 3)
               
                On Error Resume Next
               
                Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)
                If Err.Number = 0 Then
                  Ntab = Ntab + 1
                  With Worksheets(Ntab)
                        yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1
                        If yy < 1 Then yy = 2
                        .Cells(yy, 1) = Acol
                        .Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"
                        .Cells(yy, 2) = Bcol

                        For x = 3 To 8
                            .Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)
                        Next x
                  End With
                End If
            End If
        Next y
    End With

    ans = MsgBox("Ready")
End Sub


Sub OLD_BallSet()
    Application.ScreenUpdating = False

    Sheets("Data").Activate
    Sheets("Data").Columns("J:L").ClearContents
   
    max_tabs = Worksheets.Count
    y = 1
    For Tabs = 2 To max_tabs
        yy = 2
        Do
          If Sheets(Tabs).Cells(yy, 1) <> Empty Then
              For x = 1 To 3
                  Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)
              Next x
              y = y + 1
          End If
          yy = yy + 1
        Loop Until Sheets(Tabs).Cells(yy, 1) = Empty
    Next Tabs

    Sheets("data").Sort.SortFields.Clear
    Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With Sheets("data").Sort
        .SetRange Range("J1:L" & y - 1)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


    With Sheets("data")
        prev_year = -1
        y = 1
        yy = 1
        If .Cells(yy, 10) = Empty Then Exit Sub

        With .Columns("A:H")
              .ClearContents
              .UnMerge
              .Interior.ColorIndex = xlNone
              With .Font
                  .Underline = xlNone
                  .Bold = True
                  .Size = 7
              End With
        End With

        Do
            If Year(.Cells(yy, 10)) <> prev_year Then
              .Cells(y, 1) = "Date"
              .Cells(y, 2) = "Ballset"
              .Cells(y, 3) = "Numbersdrawn"
              .Cells(y + 1, 1) = "year"
              .Cells(y + 1, 2) = Year(.Cells(yy, 10))
              .Range(.Cells(y, 3), .Cells(y, 8)).Merge

              With .Range(.Cells(y, 1), .Cells(y + 1, 8))
                    .Interior.ColorIndex = 6
                    .Font.Underline = xlUnderlineStyleSingle
              End With

              prev_year = .Cells(y + 1, 2)
              y = y + 2
            End If

            .Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")
            .Cells(y, 1).NumberFormat = "@"
            .Cells(y, 2) = .Cells(yy, 11)

            For x = 3 To 8
                .Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)
                .Cells(y, x).NumberFormat = "00"
            Next x

            .Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")
            .Cells(y + 1, 1).NumberFormat = "@"
            y = y + 2
            yy = yy + 1
            .Columns("J:L").ClearContents
            .Range("I3").Select
      End With
    Loop Until .Cells(yy, 10) = Empty
End Sub
Narayan
 
Hi ,

All you need to do is separate the keywords :
Code:
Sub BallSet()
    max_tabs = Worksheets.Count
    For Tabs = 2 To max_tabs
        With Sheets(Tabs)
            y_max = .Cells(Rows.Count, 1).End(xlUp).Row
            If y_max > 1 Then
                .Activate
                .Range("A2:H" & y_max).ClearContents
            End If
        End With
    Next Tabs

    With Sheets("data")
        .Select
        y_max = .Cells(Rows.Count, 1).End(xlUp).Row
        For y = 3 To y_max Step 2
            Acol = .Cells(y, 1)
            If IsDate(Acol) Then
                Bcol = .Cells(y, 2)
                Ccol = .Cells(y, 3)
              
                On Error Resume Next
              
                Ntab = WorksheetFunction.Find(Bcol, "ABCDEF", 1)
                If Err.Number = 0 Then
                  Ntab = Ntab + 1
                  With Worksheets(Ntab)
                        yy = .Cells(Rows.Count, 1).End(xlUp).Row + 1
                        If yy < 1 Then yy = 2
                        .Cells(yy, 1) = Acol
                        .Cells(yy, 1).NumberFormat = "mmm-dd, yyyy"
                        .Cells(yy, 2) = Bcol

                        For x = 3 To 8
                            .Cells(yy, x) = Mid(Ccol, 1 + (x - 3) * 3, 2)
                        Next x
                  End With
                End If
            End If
        Next y
    End With

    ans = MsgBox("Ready")
End Sub


Sub OLD_BallSet()
    Application.ScreenUpdating = False

    Sheets("Data").Activate
    Sheets("Data").Columns("J:L").ClearContents
  
    max_tabs = Worksheets.Count
    y = 1
    For Tabs = 2 To max_tabs
        yy = 2
        Do
          If Sheets(Tabs).Cells(yy, 1) <> Empty Then
              For x = 1 To 3
                  Sheets("data").Cells(y, 9 + x) = Sheets(Tabs).Cells(yy, x)
              Next x
              y = y + 1
          End If
          yy = yy + 1
        Loop Until Sheets(Tabs).Cells(yy, 1) = Empty
    Next Tabs

    Sheets("data").Sort.SortFields.Clear
    Sheets("data").Sort.SortFields.Add Key:=Range("J1:J" & y - 1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With Sheets("data").Sort
        .SetRange Range("J1:L" & y - 1)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


    With Sheets("data")
        prev_year = -1
        y = 1
        yy = 1
        If .Cells(yy, 10) = Empty Then Exit Sub

        With .Columns("A:H")
              .ClearContents
              .UnMerge
              .Interior.ColorIndex = xlNone
              With .Font
                  .Underline = xlNone
                  .Bold = True
                  .Size = 7
              End With
        End With

        Do
            If Year(.Cells(yy, 10)) <> prev_year Then
              .Cells(y, 1) = "Date"
              .Cells(y, 2) = "Ballset"
              .Cells(y, 3) = "Numbersdrawn"
              .Cells(y + 1, 1) = "year"
              .Cells(y + 1, 2) = Year(.Cells(yy, 10))
              .Range(.Cells(y, 3), .Cells(y, 8)).Merge

              With .Range(.Cells(y, 1), .Cells(y + 1, 8))
                    .Interior.ColorIndex = 6
                    .Font.Underline = xlUnderlineStyleSingle
              End With

              prev_year = .Cells(y + 1, 2)
              y = y + 2
            End If

            .Cells(y, 1) = Format(.Cells(yy, 10), "mmm-dd")
            .Cells(y, 1).NumberFormat = "@"
            .Cells(y, 2) = .Cells(yy, 11)

            For x = 3 To 8
                .Cells(y, x) = Mid(.Cells(yy, 12), 1 + (x - 3) * 3, 2)
                .Cells(y, x).NumberFormat = "00"
            Next x

            .Cells(y + 1, 1) = Format(.Cells(yy, 10), "mmm-dd")
            .Cells(y + 1, 1).NumberFormat = "@"
            y = y + 2
            yy = yy + 1
            .Columns("J:L").ClearContents
            .Range("I3").Select
      End With
    Loop Until .Cells(yy, 10) = Empty
End Sub
Narayan

Hi Narayan:

I test your macro, but Excel 2007 show :
Compile error
End With without With

Which recommends me to repair this error.

Thank you for your help and time.

FEBAUSA
 
Back
Top