How to append data from a column in one worksheet to the bottom row in another

时间:2022-12-30 20:11:02

I couldn't find anything that matches my criteria. So i'm sorry if I missed something.

我找不到符合我标准的任何东西。如果我错过了什么,我很抱歉。

I'm trying to figure out how to take several values in specific cells in one worksheet. We'll call them:

我试图弄清楚如何在一个工作表中的特定单元格中取几个值。我们称之为:

Sheet1

Range("C5")

Range("C10")

Range("C15")

Range("C20")

and want to write a Sub that will place those 4 values in the next available row on Sheet2, with a time stamp in the first column.

并且想要编写一个Sub,它将这4个值放在Sheet2的下一个可用行中,并在第一列中加上时间戳。

2 个解决方案

#1


0  

Use end(xlup) to track the last row, e.g.:

使用end(xlup)跟踪最后一行,例如:

dim lTargetRow as long

lTargetRow=sheets("Sheet2").cells(rows.count,2).end(xlup).row+1 'find first available row

sheets("Sheet2").cells(ltargetrow,2)=sheets("Sheet1").range("C5").value
sheets("Sheet2").cells(ltargetrow,1)=now() 'add time stamp

#2


0  

Give this a try:

尝试一下:

Sub dural()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1
    k = 2
    For i = 5 To 20 Step 5
        s1.Cells(i, "C").Copy s2.Cells(n, k)
        k = k + 1
    Next i
    s2.Cells(n, 1) = Now
End Sub

#1


0  

Use end(xlup) to track the last row, e.g.:

使用end(xlup)跟踪最后一行,例如:

dim lTargetRow as long

lTargetRow=sheets("Sheet2").cells(rows.count,2).end(xlup).row+1 'find first available row

sheets("Sheet2").cells(ltargetrow,2)=sheets("Sheet1").range("C5").value
sheets("Sheet2").cells(ltargetrow,1)=now() 'add time stamp

#2


0  

Give this a try:

尝试一下:

Sub dural()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1
    k = 2
    For i = 5 To 20 Step 5
        s1.Cells(i, "C").Copy s2.Cells(n, k)
        k = k + 1
    Next i
    s2.Cells(n, 1) = Now
End Sub