VBA to loop thru column and copy/paste based on cell criteria.

BPW

New Member
Joined
Mar 7, 2013
Messages
31
Office Version
  1. 365
Platform
  1. Windows
I'm stuck on some VBA and was wondering if someone could help.

I have a column that I would like a macro to step through and:
  • Find an employee's K ID, in Col A, which always begins with a K but is variable in the number of trailing numeric digits, between 6-7.
    • If found, copy and paste into the same row, Col C.
    • Copy the name below the K ID in Col A and paste directly beside the K ID in the above row, Col D.
  • Loop until first empty cell in Col A.
View attachment 73400

Thanks for your help!
 

Attachments

  • kid.png
    kid.png
    5.8 KB · Views: 5

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Do you really need VBA?
This can be done with a few simple formulas.

Formula in cell C1:
Excel Formula:
=IF(AND(LEN(A1)>=7,LEN(A1)<=8,LEFT(A1)="K"),A1,"")

Formula in cell D1:
Excel Formula:
=IF(LEFT(C1,1)="K",A2,"")

And then copy those two formulas down to your last row of data.
 
  • Like
Reactions: BPW
Upvote 0
Solution
Very creative! This works perfectly and much simpler than the original approach. Thank you Joe4!
 
Upvote 0
You are welcome!
Glad I was able to help.
 
  • Like
Reactions: BPW
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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