Cut & Paste using Vlookup

DeadlyGentleman

New Member
Joined
Mar 31, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
New to VBA

I am trying to cut and paste data that I find using Vlookup into a different sheet

Example: Data is logged in sheet3.Range("A2:B300") with the employee's name in A and the data I need in Column B

I want to search Column A for names found in sheet1.range("A6:A45") the reason for this is that the names do not come in order and may not always be within cell("A16")

Once the name is found I need to Cut the Data 1 column right of the names (Column B) and the paste it into sheet1.Range("A6:A45")

I feel like Vlookup is the best way to find the name and the data, but I struggle with copying the data into the other sheet.

Thank you for your help, any advice is welcomed
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You want to cut the name, not copy?

So you want to loop through Sheet1!A6:A45. For each value, look it up on Sheet3, and add the value found in column B to column B in Sheet1.

Why do you need VBA for this? Why not just use a VLOOKUP formula in Sheet1!B6:B45?
 
Upvote 0
You want to cut the name, not copy?

So you want to loop through Sheet1!A6:A45. For each value, look it up on Sheet3, and add the value found in column B to column B in Sheet1.

Why do you need VBA for this? Why not just use a VLOOKUP formula in Sheet1!B6:B45?
I have attached pictures of the Source & the Paste Area.

I don't want to cut the name. I want to cut the timestamp and log it into the "Time In" column. That way I can delete empty cells & the name next to the empty cell in order to reduce multiple values, that way when employees clock in and clock out, the VBA isn't having to sort through duplicate names when the employee clocks out/clocks in and so on.

I have more than one function going into this VBA, just trying to find help for the part that is stumping me currently.
 

Attachments

  • VBA Help.png
    VBA Help.png
    148.9 KB · Views: 13
  • VBA Help1.png
    VBA Help1.png
    12.8 KB · Views: 13
Upvote 0
Not possible to test without your file and test data
VBA Code:
Public Sub CutPasteTimeStamps()

   Dim R As Long ' row number on Sheet3
   Dim Found As Range
   
   R = 2
   With Sheet3
      For R = 2 To .Cells(.Rows.Count, "A").End(xlUp).row
         Set Found = Sheet1.Range("A:A").Find(what:=.Cells(R, "A"), LookIn:=Values, lookat:=xlWhole)
         If Found Is Nothing Then
            MsgBox "Name """ & .Cells(R, "A") & """ not found on Sheet1"
         Else
            Sheet1.Cells(Found.row, "B").Cut
            .Cells(R, "B").PasteSpecial
            Application.CutCopyMode = False
         End If
      Next R
   End With
      
   Loop

End Sub
 
Upvote 0
Solution
Not possible to test without your file and test data
VBA Code:
Public Sub CutPasteTimeStamps()

   Dim R As Long ' row number on Sheet3
   Dim Found As Range
  
   R = 2
   With Sheet3
      For R = 2 To .Cells(.Rows.Count, "A").End(xlUp).row
         Set Found = Sheet1.Range("A:A").Find(what:=.Cells(R, "A"), LookIn:=Values, lookat:=xlWhole)
         If Found Is Nothing Then
            MsgBox "Name """ & .Cells(R, "A") & """ not found on Sheet1"
         Else
            Sheet1.Cells(Found.row, "B").Cut
            .Cells(R, "B").PasteSpecial
            Application.CutCopyMode = False
         End If
      Next R
   End With
     
   Loop

End Sub
Had some help on a different forum and got it solved. Much appreciated for your time & effort.
 
Upvote 0
There is a rule here that requires providing the link if you post the same question on a different forum. As it is I feel as though my time & effort was wasted since I did not know you got it solved somewhere else.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Please provide links to any other sites where you have asked this question.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,927
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top