Results 1 to 10 of 12

Thread: User Form entry in a second sheet - need help with VBA code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Hello Atlantis764
    Welcome to ExcelFox

    I don’t have any experience with UserForms
    and
    I don’t really understand the full picture of what you are trying to do.

    Here is a screenshot of the file you uploaded: https://excelfox.com/forum/showthrea...ll=1#post16365

    I can see that there is some correlation in the coloured cells, but all I can understand from your explanation is that you want to match Name and Project and Task as you showed in the workbook

    The best I can do is that I can get you started on doing that matching:

    We can make an array which has as many elements as there are data rows in Database1
    Each element will contain a string made up from each row of the
    Name & Project & Task

    We can do something similar for worksheet Database

    Then you can match the strings in the two arrays.

    Run this demo macro and I think you will see what I mean


    Code:
    '    https://excelfox.com/forum/showthread.php/2783-User-Form-entry-in-a-second-sheet-need-help-with-VBA-code?p=16371&viewfull=1#post16371
    Sub MatchNameProjectTask()
    Rem 0 Worksheets info
    Dim WsD As Worksheet, WsD1 As Worksheet
     Set WsD = ThisWorkbook.Worksheets("Database"): Set WsD1 = ThisWorkbook.Worksheets("Database1")
    Dim LrD As Long, LrD1 As Long
     Let LrD = WsD.Range("A" & WsD.Rows.Count & "").End(xlUp).Row: Let LrD1 = WsD1.Range("A" & WsD1.Rows.Count & "").End(xlUp).Row
    Rem 2 make arrays of concatenated words
    'Dim v: v = WsD.Evaluate("=D2:D4&E2:E4&F2:F4"): v = WsD.Evaluate("=D2:D" & LrD & "&E2:E" & LrD & "&F2:F" & LrD & "")
    Dim arrD() As Variant: Let arrD() = WsD.Evaluate("=D2:D" & LrD & "&E2:E" & LrD & "&F2:F" & LrD & "")
    Dim arrD1() As Variant: Let arrD1() = WsD1.Evaluate("=A2:A" & LrD1 & "&B2:B" & LrD1 & "&C2:C" & LrD1 & "")
    Rem 3 compare arrays
    Dim rwD As Long, rwD1 As Long
        For rwD = 2 To LrD
            For rwD1 = 2 To LrD1
                If arrD(rwD - 1, 1) = arrD1(rwD1 - 1, 1) Then MsgBox prompt:="match for " & arrD(rwD - 1, 1) & " at Database row " & rwD & " Database1 row " & rwD1
            
            Next rwD1
        Next rwD
    End Sub
    
    Here's the same basic macro done slightly differently
    Code:
    Sub MatchNameProjectTask2()
    Rem 0 Worksheets info
    Dim WsD As Worksheet, WsD1 As Worksheet
     Set WsD = ThisWorkbook.Worksheets("Database"): Set WsD1 = ThisWorkbook.Worksheets("Database1")
    Dim LrD As Long, LrD1 As Long
     Let LrD = WsD.Range("A" & WsD.Rows.Count & "").End(xlUp).Row: Let LrD1 = WsD1.Range("A" & WsD1.Rows.Count & "").End(xlUp).Row
    Rem 2 make arrays of concatenated words
    Dim arrD() As String, arrD1() As String
     ReDim arrD(2 To LrD): ReDim arrD1(2 To LrD1)
    Dim rwD As Long, rwD1 As Long
        For rwD = 2 To LrD
         Let arrD(rwD) = WsD.Range("D" & rwD & "") & WsD.Range("E" & rwD & "") & WsD.Range("F" & rwD & "")
        Next rwD
        For rwD1 = 2 To LrD1
         Let arrD1(rwD1) = WsD1.Range("A" & rwD1 & "") & WsD1.Range("B" & rwD1 & "") & WsD1.Range("C" & rwD1 & "")
        Next rwD1
    Rem 3 compare arrays
        For rwD = 2 To LrD
            For rwD1 = 2 To LrD1
                If arrD(rwD) = arrD1(rwD1) Then MsgBox prompt:="match for " & arrD(rwD) & " at Database row " & rwD & " Database1 row " & rwD1
            Next rwD1
        Next rwD
    End Sub
    Alan



    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Attached Files Attached Files
    Last edited by DocAElstein; 10-02-2023 at 12:55 PM.

Similar Threads

  1. Inserting Image In VBA User Form Caption
    By littleiitin in forum Download Center
    Replies: 3
    Last Post: 02-22-2021, 03:07 PM
  2. create invoice with user form
    By anil21 in forum Excel Help
    Replies: 7
    Last Post: 02-07-2018, 04:57 PM
  3. VBA Code for User Form
    By dkesar in forum Excel Help
    Replies: 1
    Last Post: 01-02-2015, 03:19 PM
  4. Replies: 5
    Last Post: 06-13-2014, 08:37 PM
  5. Replies: 7
    Last Post: 03-11-2014, 05:38 PM

Posting Permissions

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