Consulting

Results 1 to 19 of 19

Thread: Computer Hangs

  1. #1
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location

    Computer Hangs

    Dear Expets

    When I run following procedure, then computer hangs then I have to press ALT+CTRL+DEL or Power off.
    What is wrong? Please help
    [vba]
    Sub Findunique()
    Dim dateRay As Range
    Dim xVal As Variant
    Dim myColl As New Collection
    Dim FDATE As Date
    Dim LDATE As Date

    FDATE = Sheets("Rpt_Date").TextBox1.Value '01-07-06
    LDATE = Sheets("Rpt_Date").TextBox2.Value '15-06-07

    With Worksheets("weights")
    Set dateRay = .Range("C2", .Range("C" & .Rows.Count).End(xlUp))
    End With

    On Error Resume Next
    For Each xVal In dateRay
    Range("B3").Value = xVal
    If DateValue(xVal.Value) >= DateValue(FDATE) _
    And DateValue(xVal.Value) <= DateValue(LDATE) Then
    myColl.Add Item:=xVal.Offset(0, 1), key:=CStr(xVal.Offset(0, 1))
    End If
    Next xVal
    On Error GoTo 0

    Sheets("Rpt_date").ComboBox1.CLEAR

    For Each xVal In myColl
    Sheets("rpt_date").ComboBox1.AddItem xVal
    Next xVal

    End Sub
    [/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post your workbook?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    I have overcome the problem
    The following line of code was reason to hangs up
    [vba]
    Range("B3").Value = xVal
    [/vba]

    But code takes more than 10 seconds to display results
    Is it possible to SPEED UP codes?
    Please modify

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Why not filter unique items to another location and use that range to fill your combobox?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    Dear Sir

    Where to Add autofilter unique:=true in the following procedrue

    [vba]
    rng.AutoFilter Field:=4, Criteria1:="<>" ' I want to filter all unieque records from Field4
    rng.AutoFilter Field:=12, Criteria2:=(Sheets("Rpt_date").TextBox1.Value), _
    Operator:=xlOr, Criteria2:=(Sheets("Rpt_date").TextBox2.Value)
    [/vba]

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Use Advanced Filter, not Autofilter

    [vba]Sub Macro1()
    Range("A1:A26").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
    "K1"), Unique:=True
    ActiveSheet.ComboBox1.List() = Range(Range("K2"), Range("K2").End(xlDown)).Value
    Range(Range("K1"), Range("K1").End(xlDown)).ClearContents
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    But how to adjust following Date range criteria in your Advance Filter
    [vba]
    rng.AutoFilter Field:=12, Criteria2:=(Sheets("Rpt_date").TextBox1.Value), _
    Operator:=xlOr, Criteria2:=(Sheets("Rpt_date").TextBox2.Value)
    [/vba]

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As I requested in Post #2, can you post your workbook.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    Dear Sir,
    The attachment is workbook
    Please Review sheet2

  10. #10
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Eh, there isn't a Sheet2 in your attachment.

    Do you mean the sheet called Rpt_Dare?

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Option Explicit
    Sub Macro1()
    Dim rng As Range, cel As Range, Dte1 As Date, Dte2 As Date

    With Sheets("Weights")
    Range(.Cells(1, 12), .Cells(1, 12).End(xlDown)).AdvancedFilter _
    Action:=xlFilterCopy, CriteriaRange:=.Cells(2, 12), CopyToRange:=.Cells(1, 26), Unique:=True
    Set rng = Range(.Cells(2, 26), .Cells(2, 26).End(xlDown))
    rng.Sort rng(1), xlAscending
    Dte1 = CDate(Sheets("Rpt_Date").TextBox1.Value)
    Dte2 = CDate(Sheets("Rpt_Date").TextBox2.Value)
    For Each cel In rng
    If cel >= Dte1 And cel <= Dte2 Then
    Sheets("Rpt_Date").ComboBox1.AddItem cel
    End If
    Next
    Range(.Cells(1, 26), .Cells(1, 26).End(xlDown)).ClearContents
    End With
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    Run-Time Error '1004'
    Method 'Range' of object worksheet' failed.
    and debug shows error in following two lines
    [vba]
    Range(.Cells(1, 12), .Cells(1, 12).End(xlDown)).AdvancedFilter _
    Action:=xlFilterCopy, CriteriaRange:=.Cells(2, 12), CopyToRange:=.Cells(1, 26), Unique:=True
    [/vba]
    Please modify

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try recording a macro to carry out the operation and compare the codes.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #14
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    But I do not know how to adjust more than one criteria in Advance Filter.
    Please help at this final touch.

  15. #15
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    This works for me. What version of Excel are you using?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  16. #16
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi tqm1,

    If you must Xpost _please_ provide a link to the other post at least.

    http://www.ozgrid.com/forum/showthread.php?t=72302

    Here's my version of your sheet with mdmackillop's code slightly revised for the problems I was having testing in Excel '97. Figured that would provide as many problems as possible!

    Two main problems:

    Filtering with copy was not happy because it wasn't from the activesheet.

    Min Date was fine but Max Date was returning invalid date with format as dd-mm-yy. Date in textbox 21-7-06 returned as 6-7-21 . Changed format to mm-dd-yy and it works fine.

    I reactivated the Sheet Activate sub so it now fills the textboxes with default dates.

    This is now a working version. Type a date in the textboxes and you're good to go. Blank or invalid date you get a message.

    Cheers,

    dr

  17. #17
    VBAX Contributor
    Joined
    May 2007
    Posts
    128
    Location
    Dear Sir,

    In combobox1, your codes displays unique Dates from column L.

    But as I mentioned before that I want to show unique values from Column "D" against date range given in textbox1 and texbox2.

    So I changed cell referece to column 4
    [vba]
    'Advanced filter
    Range(Cells(1, 4), Cells(1, 4).End(xlDown)).AdvancedFilter _
    Action:=xlFilterCopy, CriteriaRange:=Cells(2, 12), CopyToRa
    [/vba]

    Now nothing is appear in combobox.

    this is column D
    vno9098/LI1.C.CART1.C.CART1.C.CART

    Please help again

  18. #18
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,058
    Location
    It seems that tqm1, pays no attention to the requests to link any cross posts. It is not the first time that tqm1 has cross posted and in my humble opinion, tqm1 has been mining code from more than one site.

    I would suggest that tqm1 needs to spend some time in isolation.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  19. #19
    Administrator
    Chat VP VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by rbrhodes
    Hi tqm1,

    If you must Xpost _please_ provide a link to the other post at least.

    http://www.ozgrid.com/forum/showthread.php?t=72302 ...
    tqm1,

    You have been banned (again) from posting on the VBAX forums. The reason being: For cross-posting.

    You have been warned many times about this and have previousy had a 48 hour ban imposed by me yet you still persist.

    This time the ban will apply for 96 hours, should you wish to contest this, please email me or any other Administrator. The period I have banned you for may then be reviewed as to whether I may have been too harsh (or too lenient).

    This free time is to allow you to review your situation. Please be warned that you cannot continue wasting helpers time by cross-posting - it would be far easier to place a permanent ban on you posting on VBAX.

    Have a nice day,
    John
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

Posting Permissions

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