简体   繁体   English

VBA代码可将值从一个单元格复制到特定列

[英]VBA code to copy value from one cell to specific column

I am very new to VBA and need help for the following: 我刚接触VBA,需要以下方面的帮助:

  1. Copy value from cell B3, B4, B5, B6, B7 in Worksheet "WORKING" 从工作表“工作”中的单元格B3,B4,B5,B6,B7复制值
  2. paste the value those of cells to Range (F2, lastrow), (G2, lastrow), (H2, last row), (I2, lastrow), (J2, lastrow) respectively in Worksheet "TRACKING" 将单元格的值分别粘贴到工作表“跟踪”中的范围(F2,lastrow),(G2,lastrow),(H2,last row),(I2,lastrow),(J2,lastrow)

*The "lastrow" in Worksheet "TRACKING" will always vary *工作表“ TRACKING”中的“ lastrow”将始终有所不同

*cell B3, B4, B5, B6, B7 will always have different values *单元格B3,B4,B5,B6,B7始终具有不同的值

For example 例如

Sheets"WORKING" 床单“工作”

B3 is A1234
B4 is A
B5 is B
B6 is 1
B7 is XX

Sheets"TRACKING" lastrow determined to be 4 using code lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row 使用代码lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row确定工作表“ TRACKING”的lastrow为4

Output desired is shown below 所需的输出如下所示

           F         G         H         I         J
(Row 1)
(row 2)   A1234      A         B         1         XX
(row 3)   A1234      A         B         1         XX
(row 4)   A1234      A         B         1         XX

Hope someone can help me out!! 希望有人可以帮助我! thanks!! 谢谢!!

SOLUTION FOUND 找到的解决方案

Sub data_transpose
Dim i As Integer
Dim lastrow As Long
Dim copyRange As Range
Dim sh As Worksheet
Set copyRng = Worksheets("WORKING").Range("B3:B7")
Set sh = Worksheets("TRACKING")

lastrow = sh.Range("A2", sh.Range("A2").End(xlDown)).Rows.Count + 1

For i = 2 To lastrow
copyRng.Copy
sh.Cells(i, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,    
_SkipBlanks:=False, Transpose:=True
Next i

End Sub

this might work for you 这可能对你有用

for jj=1 to #number_of_lines_you_want
for j = 6 to 10
   for i = 3 to worksheets("WORKING").cells(2,2).End(xlDown).Row
        lastrow = worksheets("TRACKING").cells(2,j).End(xlDown).Row
        worksheets("TRACKING").cells(i,j) = worksheets("WORKING").cells(i,2).value
   next i
next j
next jj

the end(xlDown).row will give you the row of the last entry. end(xlDown).row将为您提供最后一个条目的行。

What about this? 那这个呢?

for i = 3 to 7
worksheets("WORKING").range("B3:B7").Copy
Worksheets("TRACKING").cells(i,6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True

Here is one option to get you started: 这是让您入门的一种选择:

Sub CopyData()
    Dim copyRng As Range, cl As Range, col As Integer, lastRow As Integer

    Set copyRng = Worksheets("Working").Range("B3:B7")
    col = 6 ' Denotes column F

    With Worksheets("Tracking")
        lastRow = .Cells(Rows.Count, "F").End(xlUp).Row

        For Each cl In copyRng
            .Range(.Cells(2, col), .Cells(lastRow, col)) = cl
            col = col + 1
        Next cl
    End With
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 特定列中所选单元格的VBA复制值 - VBA copy value of selected cell in specific column vba代码以查找特定值并在该列的后续单元格中复制值并粘贴到新工作表中 - vba code to find a specific value and copy value in subsequent cell in the column and paste in a new sheet VBA Excel:宏,该宏在一行中搜索特定单元格中的某个变量值,然后将值复制并粘贴到此列中 - VBA Excel : Macro that searches a row for a certain variable value from specific cell and then copy&pastes value to this column 当下拉框更改值时,使用VBA代码从单元格复制特定值 - Using VBA code to Copy Specific value from a cell when the dropdown box changes that value 如果单元格具有值,则复制到下一列同一行的VBA代码 - If cell has value copy to the next column same row vba code Excel VBA 根据第二列单元格值将列从一张表复制到另一张表 - Excel VBA to Copy Column from one sheet to another based on a second columns cell value Excel VBA从列复制值并将值粘贴到单元格中 - excel vba copy value from a column and paste value in a cell VBA代码,用于根据特定的单元格标准将单元格从一列移动到另一列 - VBA code for moving cells from one column to another based on specific cell criteria VBA-将特定值从一个工作表列复制到下一个工作表行 - VBA - Copy specific value from one sheet column to next sheet row VBA复制特定的单元格并粘贴到相邻列中 - VBA to copy a specific cell and paste into adjacent column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM