Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-09-2015, 07:18 PM
Mav Mav is offline Lookup / Paste Multi Values VBA Windows 7 32bit Lookup / Paste Multi Values VBA Office 2010 32bit
Novice
Lookup / Paste Multi Values VBA
 
Join Date: Mar 2014
Posts: 7
Mav is on a distinguished road
Default Lookup / Paste Multi Values VBA

Hello,

I'm trying to create a tool to auto populate a form from data in a log on Sheet1 to a Form on Sheet2.

Steps I would like to take:
1) Press "Transfer" button
2) Enter Transfer number
3) Form populates with all the values found for that transfer number. Even multi rows if the number appears multiple times.

I've created a sample Workbook of the general layout.

Thanks in advance!
Attached Files
File Type: xlsm Sample Macro.xlsm (20.2 KB, 10 views)
Reply With Quote
  #2  
Old 05-10-2015, 05:59 AM
Mav Mav is offline Lookup / Paste Multi Values VBA Windows 7 32bit Lookup / Paste Multi Values VBA Office 2010 32bit
Novice
Lookup / Paste Multi Values VBA
 
Join Date: Mar 2014
Posts: 7
Mav is on a distinguished road
Default

Note: I know hot to populate one row with a VLookUp function. I'm having trouble populating more than one row.
Reply With Quote
  #3  
Old 05-10-2015, 01:20 PM
NoSparks NoSparks is offline Lookup / Paste Multi Values VBA Windows 7 64bit Lookup / Paste Multi Values VBA Office 2010 32bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

What's the difference between Transfer Number and ID Number ?
Is the date for a given Transfer Number on the transfer log always the same ?

I ask because I wonder why the Transfer Form has both Transfer Number and ID Number and only one location for date.

If you don't require dates when copying your data, you may want to use range.find and .findnext rather than vlookup.
If the dates could be different, and you want them with the rest of the data, you could just filter and copy the transfer log.
Reply With Quote
  #4  
Old 05-10-2015, 02:32 PM
Mav Mav is offline Lookup / Paste Multi Values VBA Windows 7 32bit Lookup / Paste Multi Values VBA Office 2010 32bit
Novice
Lookup / Paste Multi Values VBA
 
Join Date: Mar 2014
Posts: 7
Mav is on a distinguished road
Default Remove Transfer ID From Transfer Form Sheet (Column A)

Sorry, Transfer Form wasn't suppose to have Transfer ID in column A. I've deleted it and reattached. This is a basic sample of what I need. The real form is a corporate form that has more detail complicated looking. I can use VLookUp for most because the information is the same for all rows of the Transfer Number. The Transfer Number and Date are the same for all lines of the transfer and are placed in a different section of the form. This can be done with a VLookUp.

I need to learn how to copy over the part information for all instances of the Transfer Number in the Transfer Log.
Attached Files
File Type: xlsm Sample Macro.xlsm (19.9 KB, 10 views)
Reply With Quote
  #5  
Old 05-10-2015, 03:58 PM
NoSparks NoSparks is offline Lookup / Paste Multi Values VBA Windows 7 64bit Lookup / Paste Multi Values VBA Office 2010 32bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

To find locations of the Transfer Number you might want to use range.find and .findnext
See https://msdn.microsoft.com/en-us/lib.../ff839746.aspx

Here's how it could be used in your Transfer sub
Code:
Sub Transfer()
    
TransferNumber = InputBox(Prompt:="Transfer Number?", Title:="Number?")
With Sheets("Transfer Log").Range("A:A")
    Set fndNum = .Find(TransferNumber, LookIn:=xlValues)
    If Not fndNum Is Nothing Then   '<~~ the transfer number was found
        firstAddress = fndNum.Address
        Do
            With Sheets("Transfer Form")
                'find the row to write to
                writeRow = .Cells(Rows.Count, "A").End(xlUp).Row + 1
                .Cells(writeRow, 1).Resize(1, 4).Value = fndNum.Offset(0, 2).Resize(1, 4).Value
            End With
            Set fndNum = .FindNext(fndNum)
        Loop While Not fndNum Is Nothing And fndNum.Address <> firstAddress
    End If
End With

End Sub
Reply With Quote
  #6  
Old 05-10-2015, 07:50 PM
Mav Mav is offline Lookup / Paste Multi Values VBA Windows 7 32bit Lookup / Paste Multi Values VBA Office 2010 32bit
Novice
Lookup / Paste Multi Values VBA
 
Join Date: Mar 2014
Posts: 7
Mav is on a distinguished road
Default

After looking at this for a few hours lol. I think I'm following it. Is this the line of code that pastes in the data?

.Cells(writeRow, 1).Resize(1, 4).Value = fndNum.Offset(0, 2).Resize(1, 4).Value

It looks like it grabs all of the data right of the Offset. It needs to be very specific on what is copied. There is other info in the real log to the right that doesn't go into the form. If the Transfer Number is XX00002345 then the copied data needs to be specifically C4:F4.

Learning a lot. Thanks in advance
Reply With Quote
  #7  
Old 05-10-2015, 08:42 PM
NoSparks NoSparks is offline Lookup / Paste Multi Values VBA Windows 7 64bit Lookup / Paste Multi Values VBA Office 2010 32bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Yes, that's the line but it doesn't actually paste. It makes one range equal to the other range which (apparently) is more efficient than copy and paste, also doesn't leave cells selected or highlighted or have the "marching ants" or anything that might need to be dealt with.

You can change that line to what ever is necessary. Had the "copy to cells" not been contiguous it would need to have been broken down to as many as 4 separate statements.

Point of the response was you can use .find and .findnext to get multiple rows.
fndNum is a range and from there you can use .offset(rows,columns) or like Range("C" & fndNum.Row) to pick out which ever cells you require.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup multiple values and compare different scenarios to get a specific result mws Excel 5 05-24-2014 04:52 AM
Way to insert/paste frequently used values? leemoreau Word 1 09-19-2013 03:35 AM
How can match or lookup values from two separate tables? klawk26 Excel 1 07-31-2012 09:04 PM
Multi-Variable Lookup help ebolton Excel 8 05-05-2011 05:28 AM
Word - Calculate and paste values from Excel sheet Augf87 Word 1 07-06-2009 10:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:33 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft