Page 2 of 2 FirstFirst 12
Results 41 to 61 of 61

Thread: [RESOLVED] Code Dont work

  1. #41
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    What is the error message that you get?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  2. #42
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Code Dont work

    what error?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #43

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    ok a few problems now, just realised the additem does work but it adds entries to my comboboxes causing duplicates, all i want it do is display what exists and not add anything to the comboboxes.
    alo my search function is there anyway i can get it to descend search? from bottom to top not top to bottom?

    Code:
    Private Sub Search()
    Set r = Sheets("Database").UsedRange.Find(TextBox3.Value)
            If Not r Is Nothing Then
            
        TextBox1 = r.Offset(0, -2)
        TextBox2 = r.Offset(0, -1)
        TextBox3 = r.Offset(0)
        TextBox4 = r.Offset(0, 1)
        TextBox5 = r.Offset(0, 2)
        TextBox6 = r.Offset(0, 3)
        ComboBox1.AddItem r.Offset(0, 4)
        ComboBox2.AddItem r.Offset(0, 5)
        ComboBox3.AddItem r.Offset(0, 6)
        Worksheets("ES19").Range("i7").Value = TextBox1.Value
        Worksheets("ES19").Range("i9").Value = TextBox2.Value
        Worksheets("ES19").Range("z7").Value = TextBox3.Value
        Worksheets("ES19").Range("z11").Value = TextBox4.Value
        Worksheets("ES19W").Range("i7").Value = TextBox1.Value
        Worksheets("ES19W").Range("i9").Value = TextBox2.Value
        Worksheets("ES19W").Range("z7").Value = TextBox3.Value
        Worksheets("ES19W").Range("z11").Value = TextBox4.Value

  4. #44
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    Check this Example by Hack and implement it in your code

    http://www.vbforums.com/showpost.php...35&postcount=2
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #45

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    ok sorted the code out just changed additem to text and it displays it fine now thanks,,,,
    now all i need is my search code to descend search :s

  6. #46

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    Code:
    Set r = Sheets("Database").UsedRange.Find(TextBox3.Value).Order1 = xlDescending
            If Not r Is Nothing Then
    this dont work and similar alterations dont work either, please help

  7. #47
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Code Dont work

    from msdn (f1 for help)
    SearchDirection Optional Variant. Can be one of the following XlSearchDirection constants: xlNext or xlPrevious. The default constant is xlNext.
    if you do not have help installed, why not?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #48

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    Ok ill try it mate thanks

  9. #49

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    ok added the previous code to the end of that line and then, the textbox1 argument below......now has trouble...

    also when returning time data to my textboxes it returns numbers, even though the cells are set for time display.

  10. #50
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    returning time data to my textboxes it returns numbers, even though the cells are set for time display.
    I haven't gone thru the rest of the code... Let's say the time is in Cell A1 and you want to display it in Textbox1, they try this...

    vb Code:
    1. Textbox1.Text = Format(Range("A1").Value,"HH:MM:SS")
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  11. #51

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    ok right i got this error.....application-defined or object defined error!

    when this code runs...

    Code:
    Private Sub Search()
    Set r = Sheets("Database").UsedRange.Find(TextBox3.Value).Previous
            If Not r Is Nothing Then
            
        TextBox1.Text = r.Offset(0, -2)
        TextBox2.Text = r.Offset(0, -1)
        TextBox3.Text = r.Offset(0)
        TextBox4.Text = Format(Range("A1").Value, "HH:MM:SS") = r.Offset(0, 1)
        TextBox5.Text = Format(Range("A1").Value, "HH:MM:SS") = r.Offset(0, 2)
        TextBox6.Text = r.Offset(0, 3)
        ComboBox1.Text = r.Offset(0, 4)
        ComboBox2.Text = r.Offset(0, 5)
        ComboBox3.Text = r.Offset(0, 6)
        Worksheets("ES19").Range("i7").Value = TextBox1.Value
        Worksheets("ES19").Range("i9").Value = TextBox2.Value
        Worksheets("ES19").Range("z7").Value = TextBox3.Value
        Worksheets("ES19").Range("z11").Value = TextBox4.Value
        Worksheets("ES19").Range("b29").Value = ComboBox1.Value
        Worksheets("ES19W").Range("i7").Value = TextBox1.Value
        Worksheets("ES19W").Range("i9").Value = TextBox2.Value
        Worksheets("ES19W").Range("z7").Value = TextBox3.Value
        Worksheets("ES19W").Range("z11").Value = TextBox4.Value
        Worksheets("ES19W").Range("b29").Value = ComboBox1.Value
    i think its the .previous on the beginning search line that causes the problem because it works without that, but i need the search to go in that direction.

  12. #52
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Code Dont work

    xlprevious is a constant, not a method or property, it has to be an argument passed to the find method

    read the help file or search on line

    also your textbox4 and 5 code is wrong
    Last edited by westconn1; Oct 8th, 2009 at 04:26 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #53

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    THIS IS IT.zip

    ok koolsid, here is the file i mentioned.

  14. #54
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    I will get to your time problem later. First let's tackle the .Find issue...

    Is this what you want?

    vb Code:
    1. Private Sub Search()
    2.     Dim myAddr As String, MyArray() As String, r As Range
    3.    
    4.     '~~> Get the used range address
    5.     myAddr = Sheets("Database").UsedRange.Address
    6.     '~~> Split the address to get the last cell
    7.     MyArray = Split(myAddr, ":")
    8.     '~~> Select the last cell
    9.     Range(MyArray(1)).Select
    10.    
    11.     strSearch = Trim(TextBox3.Value)
    12.    
    13.     '~~> Using xlPrevious to find in reverse
    14.     Set r = Cells.Find(What:=strSearch, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
    15.     xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False _
    16.     , SearchFormat:=False)
    17.    
    18.     If Not r Is Nothing Then
    19.         TextBox1.Text = r.Offset(0, -2)
    20.         TextBox2.Text = r.Offset(0, -1)
    21.         '
    22.         '~~> Your Rest of the code
    23.         '
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  15. #55

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    thats good does what i want it too, but that code caused textbox1 to return a figure now instead of text....


    textbox1 - text - did display correctly - now displays a number instead of text
    textbox2 - text - displays correctly
    textbox3 - text - displays correctly
    textbox4 - time - doesnt display correctly - displays a number instead of time
    textbox5 - time - doesnt display correctly - displays a number instead of time
    textbox6 - date - displays correctly
    textbox7 - text - displays correctly

  16. #56
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    I just amended/worked on the .find issue...

    I didn't check the code between

    If Not r Is Nothing Then

    Endif
    Check if the offset code is correct for each one of them...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  17. #57

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    yes i had a duplicate textbox1 there so now just the problem of getting 4 and 5 to show time no matter what cell the data comes from....

  18. #58
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    Try this

    vb Code:
    1. '
    2.         '~~> Your Rest of the code
    3.         '
    4.         TextBox4.Text = Format(r.Offset(0, 1), "HH:MM:SS")
    5.         TextBox5.Text = Format(r.Offset(0, 2), "HH:MM:SS")
    6.         '
    7.         '~~> Your Rest of the code
    8.         '
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  19. #59

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    Darn It! why is it when u try it works so simply, yet i try everything everyway round and get nowhere thanks mate that is perfect and works a treat.

  20. #60
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Code Dont work

    Quote Originally Posted by hensucker View Post
    Darn It! why is it when u try it works so simply, yet i try everything everyway round and get nowhere thanks mate that is perfect and works a treat.


    Hope all your queries are resolved?
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  21. #61

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2009
    Location
    England!
    Posts
    364

    Re: Code Dont work

    thaks buddy sorted

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width