Using Vlookup to copy and paste data into a separate worksheet using VBA

Willarci3

Alright I'm a beginner with VBA so I need some help. Assuming this is very basic, but here are the steps I am looking at for the code:

-Use Vlookup to find the value "Rec" in column C of Sheet1, and select that row's corresponding value in column D

-Then copy that value from column D in Sheet1 and paste it into the first blank cell in column B of another worksheet titled Sheet2

I've got a basic code that uses Vlookup to find Rec as well as it's corresponding value in column D, then display a msg. The code works fine, and is the following:

Sub BasicFindGSV()
Dim movement_type_code As Variant
Dim total_gsv As Variant
movement_type_code = "Rec"
total_gsv = Application.WorksheetFunction.VLookup(movement_type_code,Sheet1.Range("C2:H25"), 2, False)
MsgBox "GSV is :$" & total_gsv
End Sub

I also have another one that will find the next blank cell in column B Sheet2, it works as well:

Sub SelectFirstBlankCell()
Dim Sheet2 As Worksheet
Set Sheet2 = ActiveSheet
For Each cell In Sheet2.Columns(2).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
End Sub

Not sure how to integrate the two, and I'm not sure how to make the code paste the Vlookup result in Sheet2. Any help would be greatly appreciated, thanks!

SierraOscar

Try this:

Sub MacroMan()

    Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = _
        WorksheetFunction.VLookup("Rec", Sheet1.Range("C2:H25"), 2, False)

End Sub

The Range("B" & Rows.Count).End(xlUp) command is the equivalent of going to the last cell in column B and pressing Ctrl +

We then use .Offset(1, 0) to get the cell after this (the next blank one) and write the value of your vlookup directly into this cell.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

copy and paste specific cell(using .find) in worksheet array using vba

Copy and paste a row of data into separate rows and staggered columns using Excel VBA macro

How to copy/paste Values after using VLookup

Copy paste using VBA in excel

VBA Copy and Paste to new Worksheet

How to copy and paste data from Horizontal to Vertical using vba

#copy from excel and paste to notepad using VBA

Copy and Paste a Range of Cells using VBA

Copy and Paste from Excel to PowerPoint using VBA

How to copy a range and paste diagonally using vba

Compare two columns and copy paste using vba

VBA copy and paste data

VBA Trigger Worksheet Change with Copy/Paste

Copy and paste value to another worksheet by VBA

VBA Copy and Paste after Vlookup is performed

How to copy data between two defined dates to new worksheet using VBA?

Copy/Paste worksheet to new workbook without that worksheet's VBA code

Copy and paste multiple ranges without using the clipboard using VBA

How do i copy and paste data to worksheets that i created in VBA using for loop?

How to Copy Range of Filtered Data and Paste it to new work sheet in Excel VBA (without Using Clipboard)

VBA to copy data from one sheet and paste against a range and repeat using LOOP or any other method

Copy and paste data into the same range of multiple worksheets by using a VBA module code

VBA Copy data from a selected row then paste it on a different worksheet, on specific columns

Copy Paste VBA Range from one to another worksheet Loop and transpose the data

Vba Worksheet_Change event does not trigger when copy and paste data into column but works with a manual click into cell

vlookup and if condition copy data vba

Using VBA to Paste Excel Chart with Data into PowerPoint

Copy website data using VBA

Using loops to copy and paste