+ Reply to Thread
Results 1 to 7 of 7

Transfer data from one form to another.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    60

    Transfer data from one form to another.

    Hello, I've got something like this:
    example.jpg

    I would like to transfer data from left part of picture into right part format. Name is always first and under it are listed tasks, amount of tasks is never the same. I can export Name and Date manually no problem, I just need some automation with transfering correct tasks. Any amount of help columns is welcome. I would prefer non VBA solution if possible. Thank you for any help.
    Crossposted my problem at: https://www.mrexcel.com/forum/excel-...ml#post5023857
    Attached Files Attached Files
    Last edited by Pojzon; 03-12-2018 at 11:13 AM.

  2. #2
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    60

    Re: Transfer data from one form to another.

    Is this even possible?

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,862

    Re: Transfer data from one form to another.

    Try

    Option Explicit
    Sub TransForm_Data()
    
    Dim inArr() As Variant
    Dim OutArr() As Variant
    
    Dim namex As String
    Dim i As Integer
    Dim rr As Integer
    Dim r As Long
    Dim c As Long
    Dim lastrow As Long
    Dim lastcol As Long
    
    Dim inRng As Range
    Dim outRng As Range
    
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    
    Application.ScreenUpdating = False
    ws1.Activate
    
    With ws1
    
        lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
        lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
        
        Set inRng = .Range(.Cells(2, "B"), .Cells(lastrow, lastcol))
        
        inArr = inRng
        
        ReDim OutArr(1 To 1000, 1 To 3)
        
        rr = 0
        r = 1
        Do While r < lastrow
            
            namex = inArr(r, 1)
            For i = 1 To 5
                OutArr(rr + i, 1) = namex
                OutArr(rr + i, 2) = i
            Next i
            
            r = r + 1
            Do While inArr(r, 7) <> ""
               
                For c = 2 To 6
                      If inArr(r, c) <> "" Then
                        OutArr(rr + c - 1, 3) = inArr(r, 1)
                      End If
                Next c
                
                r = r + 1
                If r >= lastrow Then GoTo output
                
            Loop
            rr = rr + 5
        Loop
        
    End With
    
    output:
    With ws2
         Set outRng = .Range(.Cells(2, 1), .Cells(rr + 6, 3))
    End With
    
    outRng = OutArr
    
    Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    60

    Re: Transfer data from one form to another.

    Nice, looks great, thank you very much for this. Could you just please tell me which part of the code should I change if I need more columns with date than 5? I can't figure this out.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,862

    Re: Transfer data from one form to another.

    Option Explicit
    Sub TransForm_Data()
    
    Dim inArr() As Variant
    Dim OutArr() As Variant
    
    Dim namex As String
    Dim i As Integer
    Dim rr As Integer
    Dim r As Long
    Dim c As Long
    Dim lastrow As Long
    Dim lastcol As Long
    
    Dim inRng As Range
    Dim outRng As Range
    
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    
    Application.ScreenUpdating = False
    ws1.Activate
    
    With ws1
    
        lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
        lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
        
        Set inRng = .Range(.Cells(2, "B"), .Cells(lastrow, lastcol))
        
        inArr = inRng
        
        ReDim OutArr(1 To 1000, 1 To 3)
        
        rr = 0
        r = 1
        Do While r < lastrow
            
            namex = inArr(r, 1)
            For i = 1 To 5  ' 5 is number of dates
                OutArr(rr + i, 1) = namex
                OutArr(rr + i, 2) = i
            Next i
            
            r = r + 1
            Do While inArr(r, 7) <> ""
               
                For c = 2 To 6   ' Column numbers starting in B =1, column c=2: g=6 (dates are c to G currently)
                      If inArr(r, c) <> "" Then
                        OutArr(rr + c - 1, 3) = inArr(r, 1)
                      End If
                Next c
                
                r = r + 1
                If r >= lastrow Then GoTo output
                
            Loop
            rr = rr + 5  ' 5 is number of dates
        Loop
        
    End With
    
    output:
    With ws2
         Set outRng = .Range(.Cells(2, 1), .Cells(rr + 6, 3))' Nunber of dates +1
    End With
    
    outRng = OutArr
    
    Application.ScreenUpdating = True
    
    End Sub

    UNTESTED!

    Post a sample file.
    Last edited by JohnTopley; 03-11-2018 at 02:36 PM.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,862

    Re: Transfer data from one form to another.

    Updated code

    Option Explicit
    Sub TransForm_Data()
    
    Dim inArr() As Variant
    Dim OutArr() As Variant
    
    Dim namex As String
    Dim i As Integer
    Dim rr As Integer
    Dim r As Long
    Dim c As Long
    Dim Ndates As Integer
    Dim lastrow As Long
    Dim lastcol As Long
    
    Dim inRng As Range
    Dim outRng As Range
    
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets("Sheet2")
    
    Application.ScreenUpdating = False
    ws1.Activate
    
    Ndates = 6  ' Number of dates
    
    With ws1
    
        lastrow = .Cells(Rows.Count, "B").End(xlUp).Row
        lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
        
        Set inRng = .Range(.Cells(2, "B"), .Cells(lastrow, lastcol))
        
        inArr = inRng
        
        ReDim OutArr(1 To 1000, 1 To 3)
        
        rr = 0
        r = 1
        Do While r < lastrow
            
            namex = inArr(r, 1)
            For i = 1 To Ndates
                OutArr(rr + i, 1) = namex
                OutArr(rr + i, 2) = i
            Next i
            
            r = r + 1
            Do While inArr(r, Ndates + 2) <> ""
               
                For c = 2 To Ndates + 1
                      If inArr(r, c) <> "" Then
                        OutArr(rr + c - 1, 3) = inArr(r, 1)
                      End If
                Next c
                
                r = r + 1
                If r >= lastrow Then GoTo output
                
            Loop
            rr = rr + Ndates
        Loop
        
    End With
    
    output:
    With ws2
         Set outRng = .Range(.Cells(2, 1), .Cells(rr + Ndates + 1, 3))
    End With
    
    outRng = OutArr
    
    Application.ScreenUpdating = True
    
    End Sub

    Change value of "Ndates" (Highlighted)
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-26-2015
    Location
    Poland
    MS-Off Ver
    365
    Posts
    60

    Re: Transfer data from one form to another.

    Thank you very much!

+ 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] transfer data from form to form
    By DonG in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-30-2016, 12:54 AM
  2. Transfer data from record in continuous form to popup form?
    By krabine in forum Access Tables & Databases
    Replies: 0
    Last Post: 09-28-2015, 08:27 AM
  3. Using VBA to transfer data from Excel form to a web form. error 'Permission Denied'
    By danieldowds in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2014, 08:14 AM
  4. Search form and transfer data
    By 555Rage in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2012, 04:30 AM
  5. Transfer User form data to a worksheet w.r.t. combobox item on the form
    By nm766 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2011, 12:43 PM
  6. [SOLVED] Transfer data to form from Excel range upon loading of form.
    By Rob Crawford in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2005, 11:05 AM
  7. [SOLVED] Form 2 Form data transfer
    By Madduck in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-23-2005, 07:05 PM

Tags for this Thread

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