Results 1 to 3 of 3

Thread: Excel VBA...please help me..??

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    1

    Excel VBA...please help me..??

    Dear experts,

    I really need your help please...In Excel, I have Sheet1 (as a BOOK), Sheet2 (as a PEN) and Sheet3 (as a Payment). When we open this file, it will show the pop up first which contain as follow: Select type: BOOK or PEN, then enter the code number..For instance, if I choose BOOK, then it will fill all information from another SHEET (Sheet1 / Book) such as Code, Description and Price in the Sheet3 (Payment)....Has anyone knows how to do that please?

    To make it clear, I put an attachment for this.

    I really appreciate for your helps...thanks

    Clara
    Attached Files Attached Files
    Last edited by clara; May 4th, 2006 at 04:11 AM. Reason: need more explanation

  2. #2
    Lively Member
    Join Date
    Feb 2006
    Posts
    96

    Re: Excel VBA...please help me..??

    Hi and welcome...

    Just to make sure I understand you correctly. When you open your workbook you want a userform to pop-up. From this userform you want to choose either PEN or BOOK and then enter a code (some sort of registration number?) and when executed what should it do?

    a) Find a match for the code in Sheet BOOK, and then copy it to Sheet PAYMENT

    or b) Find a match for the code in Sheet PAYMENT, and then copy it to Sheet BOOK?

    Just to make sure

    cheers
    Nick

  3. #3
    Lively Member
    Join Date
    Feb 2006
    Posts
    96

    Re: Excel VBA...please help me..??

    Hi again - made up a little something

    Since i'm at work i can't open your attached zip file so i can't see what your sheet looks like, but

    If you make a userform on your sheet, and provides it with autoopen via the ThisWorkbook, then the following will work:

    Userform should have the following: 2 optionbuttons, one named optbook and one named optpen. 1 textbox named txtcode and 1 commandbutton named cmdgo.

    double click the commandbutton to get to the private sub for cmdgo_click and paste the following:

    VB Code:
    1. Private Sub CmdGo_Click()
    2. Dim i As Single
    3. Dim j As Single
    4. Dim bSheet As Worksheet
    5. Dim pSheet As Worksheet
    6. Dim ySheet As Worksheet
    7.  
    8.     Set bSheet = ActiveWorkbook.Worksheets("BOOK")
    9.     Set pSheet = ActiveWorkbook.Worksheets("PEN")
    10.     Set ySheet = ActiveWorkbook.Worksheets("PAYMENT")
    11.  
    12. If OptBook = True Then
    13.     For i = 1 To 100
    14.         If TxtCode.Value = bSheet.Cells(i, 1).Value Then
    15.             bSheet.Activate
    16.             bSheet.Rows(i).EntireRow.Copy
    17.             ySheet.Activate
    18.             ySheet.Cells(1, 1).End(xlDown).Offset(1, 0).PasteSpecial
    19.         End If
    20.     Next i
    21. End If
    22. If OptPen = True Then
    23.     For j = 1 To 100
    24.         If TxtCode = pSheet.Cells(j, 1).Value Then
    25.             pSheet.Activate
    26.             pSheet.Rows(j).EntireRow.Copy
    27.             ySheet.Activate
    28.             ySheet.Cells(1, 1).End(xlDown).Offset(1, 0).PasteSpecial
    29.         End If
    30.     Next j
    31. End If
    32. End Sub

    For this to work there is some things you shold be aware of - in your payment sheet, I take it that you have a header - this should be placed in row 2 (row 1 should be empty). I'm assuming that your code is in column A (this should be formatted as text). Also my for...next statement is limited to 100 rows, just correct this if necessary...

    I take it that you know basic VBA (kind like me), so then you should be able to fit it to meet your needs...

    cheers
    nick

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