+ Reply to Thread
Results 1 to 8 of 8

Userform is not working.

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2019
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    13

    Angry Userform is not working.

    Hi!
    Im trying to extract specific data between two dates into another sheet with userform. But I dont know what im doing wrong..
    all help is welcome.


    error.JPG



     Private Sub CommandButton1_Click()
    
    Dim lrow As Long, i As Long, x As Date, y As Date, erow As Long
    
    x = TextBox1
    y = TextBox2
    
    'Find the Last Row (data filled row) of Sheet1
    lrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    
    'start counting from row 2 to last row
    For i = 2 To lrow
    ' here the date balue is converted as numeric value by multiplying with number 1
    If Cells(i, 1) * 1 >= x * 1 Then
    If Cells(i, 1) * 1 >= y * 1 Then
    
    ' here i,3(the column number where Artikel found
    If Trim(Cells(i, 3)) = Trim(TextBox3.Text) Then
    
    'if above conditions matched then select the matched range or entire row
    Sheet1.Range(Cells(i, 1), Cells(i, 4)).Select
    'to copy the selected row
    Selection.Copy
    'to make sheet2 active where we want to paste the selected row
    Sheets("Sheet2").Activate
    'to find the empty row from where the copide row of sheet1 to be pasted in sheet2
    erow = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    'to activate or select the empty row of sheet2
    ActiveSheet.Cells(erow, 1).Select
    'to paste the copied row
    ActiveSheet.Paste
    'to deselect the copy and selected mode
    Application.CutCopyMode = False
    'for above the if we need 3 end if to close if conditions
    End If
    End If
    End If
    'finally to activate sheet1 for searching the mached data
    Sheets("Sheet1").Activate
    'now to continue for look until above matched found
    Next i
    End Sub
    Attached Files Attached Files
    Last edited by jhakans; 05-27-2019 at 11:30 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,455

    Re: Userform is not working.

    Code tags added by OP
    Last edited by Pepe Le Mokko; 05-24-2019 at 07:07 AM.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,455

    Re: Userform is not working.

    And while you are at it, please post a sample sheet ( pictures are useless). Click Go advanced - Manage attachments

  4. #4
    Registered User
    Join Date
    05-24-2019
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    13

    Re: Userform is not working.

    Done! Thanks

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Userform is not working.

    Try this...
    Private Sub CommandButton1_Click()
    Dim sDt As Date, eDt As Date
    sDt = TextBox1.Value: eDt = TextBox2.Value
    With Sheet1.Cells(1).CurrentRegion
        .AutoFilter 1, Criteria1:=">=" & CDbl(sDt), Operator:=xlAnd, Criteria2:="<=" & CDbl(eDt)
        .Offset(1, 0).Copy Sheet2.Range("A" & Sheet2.Cells(Rows.Count, 1).End(xlUp).Row + 1)
        .AutoFilter
    End With
    End Sub
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  6. #6
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,314

    Re: Userform is not working.

    Is this the result you are looking for.
    I have just removed the two 'Trim' conditions.
    Also with your date logic you have to set the dates one day prior and one day after.
    To stop the screen jumping about include Screen Updating False/True at start & end of code.
    torachan.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-24-2019
    Location
    Sweden
    MS-Off Ver
    2013
    Posts
    13

    Re: Userform is not working.

    Thank you so much! this was exactly what I was looking for

  8. #8
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,336

    Re: Userform is not working.

    ...................................................
    Thanks.gif

+ 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. [SOLVED] progress bar userform inside userform not working
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2018, 05:41 PM
  2. userform not working properly
    By shiva_raj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2017, 04:53 PM
  3. Why Isn't My Userform Working?
    By drsadistic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2014, 11:18 PM
  4. Printing a userform - Not working
    By excelenergy in forum Excel General
    Replies: 3
    Last Post: 03-13-2014, 03:09 PM
  5. [SOLVED] Gradually Fade Userform Into View [Userform Fade Out Working Already]
    By nadstradamus in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-05-2013, 04:12 AM
  6. Alt+Tab not working when an userform is opened
    By sivdin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2009, 06:34 AM
  7. [SOLVED] Working with Cells on Userform
    By Jeff Ingraham in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2006, 01:15 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