简体   繁体   English

VBA将基于条件从命名范围复制到另一个工作表中的粘贴Vlaues

[英]VBA to Copy from Named Range based on Condition to Paste Vlaues in another worksheet

I have a Named Range "Quantities" (Worksheet Sheet1, cells I21:L28) that have formula that reports a the quantity in column "L". 我有一个命名范围“数量”(工作表Sheet1,单元格I21:L28),其公式在“ L”列中报告了数量。 I would like to search Column L for values >0, and then Paste those Values (along with Data from Column K) into another worksheet (Sheet10). 我想在L列中搜索值> 0,然后将这些值(以及K列中的数据)粘贴到另一个工作表(Sheet10)中。 The following Code is close, but it paste the formula not the values. 下面的代码已关闭,但是粘贴了公式而不是值。 Please assist. 请协助。

Sub CopyOnCondition()
     Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
     Set sh1 = Sheet1 'Edit sheet name
     Set sh2 = Sheet10 'Edit sheet name
     With sh1
         For Each c In .Range("L18:L24")
             If c.Value > 0 Then
                 c.Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2, 1)
             End If
         Next
     End With
End Sub

Try this 尝试这个

Sub CopyOnCondition()
     Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
     Set sh1 = Sheet1 'Edit sheet name
     Set sh2 = Sheet10 'Edit sheet name
     With sh1
         For Each c In .Range("L18:L24")
             If c.Value > 0 Then
                 sh2.Cells(Rows.Count, 1).End(xlUp)(2, 1).resize(,2).value=c.offset(,-1).resize(,2).value
             End If
         Next
     End With
End Sub

The code below will copy the values only from Columns K:L when the value in column L > 0. 当L列中的值> 0时,以下代码将仅从K:L列中复制值。

Sub CopyOnCondition()

     Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
     Set sh1 = Sheet1 'Edit sheet name
     Set sh2 = Sheet10 'Edit sheet name

     With sh1
         For Each c In .Range("L18:L24")
             If c.Value > 0 Then
                 c.Offset(, -1).Resize(1, 2).Copy '<-- copy column K with L
                 ' paste values to the first empty row in Column A of sh2
                 sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial xlValues
             End If
         Next c
     End With

End Sub

暂无
暂无

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

相关问题 将粘贴范围从一个工作表复制到另一个 - Copy paste range from one worksheet to another 复制一个静态的命名范围并将其粘贴到另一个工作表中的变量单元格地址 - Copy a static named range and paste it to a variable cell adress in another worksheet Excel宏可从工作表复制单元格数据并根据特定条件粘贴到另一个工作表上 - Excel macro to copy cell data from a worksheet and paste on another worksheet based on a certain condition Excel VBA复制/粘贴范围从1个工作表到另一个,每次相同的范围粘贴到下一个目标列 - Excel VBA copy/paste range from 1 worksheet to another, same range pastes in next destination column each time Excel VBA复制/粘贴范围到另一个工作表中的下一个可用单元格 - Excel VBA Copy/Paste Range to the next available cell in another worksheet 根据条件在不同的工作表中复制/粘贴从非连续列到非连续列的一系列数据 - copy/paste a range of data from non contiguous to non-contiguous columns in a different worksheet based on condition 如何根据VBA中的预定义索引从另一个工作表复制和粘贴一系列单元格 - How to copy and paste a range of cells from another worksheet depending on predefined indices in VBA 复制单元格范围并根据日期粘贴到另一个工作表中? - Copy cell range and paste in another worksheet based on the date? 复制,粘贴基于多个条件的选择到VBA中的另一个工作表 - copy, paste selection based on multiple criteria to another worksheet in VBA 来自多个工作表的VBA Excel复制/粘贴特定范围 - VBA Excel Copy/Paste Specific Range from multiple worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM