excel - VBA - Copy specific value from one sheet column to next sheet row -


i need please, have 2 sheet, in first sheet record time against different numbers (1 50), want copy time stamp on new sheet against same number. sheet 1: sheet 1 example

sheet 2: sheet 2 example

please vba code done automatically.

sub mytry() dim lrow long dim lrow1 long dim time1 date  sheets("time").select  lrow = range("a" & rows.count).end(xlup).row  icntr = 2 lrow  num1 = cells(icntr, 1)      sheets("rec").select     lrow1 = range("a" & rows.count).end(xlup).row     icntr2 = 2 lrow1         if cells(icntr2, 1) = num1             time1 = cells(icntr2, 2)             sheets("time").select             t1 = 2 20             if cells(icntr, t1) = ""             cells(icntr, t1) = time1             end if             goto 1              next t1              1             sheets("rec").select          end if       next icntr2  sheets("time").select next icntr 

end sub

this isn't prettiest thing i've done, i'm going try...

you may want think adding few variables, since know items going on sheets("rec"):

dim integer dim lrow long 'specific sheets("time") dim lc1 long, lc2 long, lc3 long 'up lc9 in example last column row # 

taking have , rolling it, loop through sheets("time"):

lrow = sheets("time").range("a" & sheets("time").rows.count).end(xlup).row  = 2 lrow 

i recommend avoiding sheet select @ start , specifying sheets name go, or using statements (the latter might not work smoothly path i'm going select case).

you can use select case inside of loop equivalent number count, e.g., 9 example.

select case cells(i,1).value  case 1    lc1=sheets("rec").cells(2, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(2,lc1)  case 2    lc2=sheets("rec").cells(3, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(3,lc2)  case 3    lc3=sheets("rec").cells(4, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(4,lc3)  end select 

then should able have run pretty smooth, making sure next i. comes looking like:

dim integer dim lrow long  dim lc1 long, lc2 long, lc3 long   lrow1 = sheets("time").range("a" & sheets("time").rows.count).end(xlup).row  = 2 lrow  select case cells(i,1).value  case 1    lc1=sheets("rec").cells(2, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(2,lc1)  case 2    lc2=sheets("rec").cells(3, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(3,lc2)  case 3    lc3=sheets("rec").cells(4, sheets("rec").columns.count).end(xltoleft).column     sheets("time").cells(i,2).copy sheets("rec").cells(4,lc3)  end select  next 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -