+ Reply to Thread
Results 1 to 10 of 10

Macro doing activities twice.

Hybrid View

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    31

    Macro doing activities twice.

    Hello Everyone,

    I have buid a code to pull counts from other files and it takes some time. While to do this i want to show User form and i have added it in my code and it is displaying it. But the problem is Macro is doing the activities twice. and i not getting where i am worng. Please help...
    PFA for the same Sample.xls

    Sub corefunction()
    Application.ScreenUpdating = False
    waitform.Show
    DoEvents
    Shstart.Select
    Dim path As Variant
    path = Range("C1").value & Range("G1").Text & "\" & Range("H1").Text & "\" & Range("i1").Text & "\"
    lastrow = Sheets("start").Cells(Rows.Count, "A").End(xlUp).Row
    XLSDirectory = path
    
    Dim Runname As String
    Dim Index As String
    
    First = True
    Do
        If First = True Then
            Xlsfilename = Dir(XLSDirectory & "*.xls")
            First = False
            Else
            Xlsfilename = Dir()
            
       End If
            If Xlsfilename <> "" Then
            Workbooks.Open Filename:=XLSDirectory & Xlsfilename
            Set oldbk = ActiveWorkbook
            
            With ThisWorkbook
            Dim wbkbname As Variant
            wbkname = ActiveWorkbook.Name
             Shstart.Activate
             Worksheets("Start").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).value = wbkname
             oldbk.Activate
             Dim ws As Worksheet
        For Each ws In Worksheets
            ws.Activate
            Dim value As Long
            Dim shname As Variant
            
            value = Application.WorksheetFunction.CountA(Range("A:A")) - 1
            Shstart.Activate
            Dim lastrow2 As Long
            lastrow2 = Range("A" & Rows.Count).End(xlUp).Row
            Range("A" & Rows.Count).End(xlUp).Select
            Cells(lastrow2, Columns.Count).End(xlToLeft).Offset(0, 1).Activate
            ActiveCell.value = value
            oldbk.Activate
            Next ws
            ActiveWorkbook.Close
    End With
    End If
                 
    Loop While Xlsfilename <> ""
    Shstart.Range("A3").Select
    
     waitform.Hide
    MsgBox "Macro Completed, Please Review...!", vbInformation, "Developed By : Deepak Sirsale"
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro doing activities twice.

    Your sample has a password on the vba project.

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Macro doing activities twice.

    Please supply the VBA project password


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    11-30-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Macro doing activities twice.

    Opss Sorry... It's Invincible

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro doing activities twice.

    Sub corefunction_1()
    Dim path As Variant
    Dim lastrow As Variant
    Dim runname As String
    Dim index As String
    Dim xlsfilename As Variant
    Dim oldbk
    Dim ws
    waitform.Show
    Application.ScreenUpdating = False
    With wbkbname.Shstart
        path = .Range("C1").value & .Range("G1").Text & "\" & .Range("H1").Text & "\" & .Range("i1").Text & "\"
        lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
        xlsfilename = Dir(path & "*.xls")
        Do Until xlsfilename = ""
            Set oldbk = Workbooks.Open(path & xlsfilename)
            .Range("A" & Rows.Count).End(xlUp).Offset(1, 0).value = oldbk.Name
            For Each ws In oldbk.Sheets
                .Range("A" & .Rows.Count).End(xlUp).Offset(0, .Columns.Count - 1).End(xlToLeft).Offset(0, 1) = _
                    WorksheetFunction.CountA(ws.Range("A:A")) - 1
            Next ws
        oldbk.Close False
        Loop
    End With
    waitform.Hide
    MsgBox "Macro Completed, Please Review...!", vbInformation
    End Sub
    Looking through your code, that is how I would do it. Not sure if it will fix your problem..

  6. #6
    Registered User
    Join Date
    11-30-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Macro doing activities twice.

    Hi yudlugar,

    Thanks for your help, but the above code is not working fine, It is selecting First file from folder and doing activities..... but not going on next file..
    and the macro is not stopping it is contineously selting first file and so on.... and also the form is displaying in white color...

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro doing activities twice.

    Oooops, I forgot an important part!
    Sub corefunction_1()
    Dim path As Variant
    Dim lastrow As Variant
    Dim runname As String
    Dim index As String
    Dim xlsfilename As Variant
    Dim oldbk
    Dim ws
    waitform.Show
    Application.ScreenUpdating = False
    With Shstart
        path = .Range("C1").value & .Range("G1").Text & "\" & .Range("H1").Text & "\" & .Range("i1").Text & "\"
        lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
        xlsfilename = Dir(path & "*.xls")
        Do Until xlsfilename = ""
            Set oldbk = Workbooks.Open(path & xlsfilename)
            .Range("A" & Rows.Count).End(xlUp).Offset(1, 0).value = oldbk.Name
            For Each ws In oldbk.Sheets
                .Range("A" & .Rows.Count).End(xlUp).Offset(0, .Columns.Count - 1).End(xlToLeft).Offset(0, 1) = _
                    WorksheetFunction.CountA(ws.Range("A:A")) - 1
            Next ws
        oldbk.Close False
        xlsfilename = dir
        Loop
    End With
    waitform.Hide
    MsgBox "Macro Completed, Please Review...!", vbInformation
    End Sub
    Last edited by ragulduy; 12-20-2013 at 08:37 AM.

  8. #8
    Registered User
    Join Date
    11-30-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Macro doing activities twice.

    Hi yudlugar,

    The Code is working fine, Except Userform... it is showing White coloured form.... and when i use Doevents then it it showing the from but same issue as my coding has.... it is running twice.....

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro doing activities twice.

    You have "corefunction" written in your userform_activate event. So when you load the userform it will repeat the code again!

    Use do events and delete the userform_activate code from the userform code module.

  10. #10
    Registered User
    Join Date
    11-30-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Macro doing activities twice.

    Oh.... !!! Thanks..... Now working perfect...!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Tracking time for activities.
    By martianrebel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2013, 05:53 PM
  2. Mapping activities to names
    By Tommy in forum Excel General
    Replies: 4
    Last Post: 02-18-2010, 09:50 AM
  3. Chart XY TIME - Activities like GANTT
    By riccardo79 in forum Excel General
    Replies: 16
    Last Post: 01-06-2009, 03:00 PM
  4. Activities? Schimivities!
    By username in forum Excel General
    Replies: 0
    Last Post: 05-23-2005, 02:06 PM
  5. [SOLVED] Network activities while runnung macros
    By augustus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2005, 11:06 PM

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