简体   繁体   English

VBA宏-根据单元格值从下面复制部分行

[英]VBA Macro - Copy Partial Row from Below Based on Cell Value

I'm really new to VBA and trying to figure out how to create a loop so that, when the value in column A is “1”, the values from columns E to N in the row immediately below are copied to the row above (without inserting a new row, just pasting over the existing values). 我真的是VBA的新手,试图弄清楚如何创建一个循环,以便当A列中的值为“ 1”时,将紧接在下一行的E到N列的值复制到上一行(无需插入新行,只需粘贴现有值即可)。 I've been through the course book and dozens of Excel forums and can't see a way of doing this? 我已经看过课程书和数十个Excel论坛,看不到这样做的方法吗? Is it possible? 可能吗?

Thanks, Adam 谢谢亚当

Something like this should work 这样的事情应该工作

Sub test()
   Dim n as Integer
   Dim i As Integer
   n = 100
   For i = 1 To n
       If CInt(Range("a" & i)) = 1 Then
           Range("e" & i + 1 & ":n" & i + 1).Copy
           Range("e" & i).PasteSpecial xlPasteValues
       End If
   Next i

   Application.CutCopyMode = False
End Sub

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

相关问题 VBA 根据日期将工作表 1 中的单元格值复制/粘贴到工作表 2 的宏 - VBA Macro to copy/paste cell value from sheet 1 to 2 based on date 如何使用宏vba在Excel中基于相邻单元格数据将单元格数据复制到下面的单元格数据? - How to copy cell data to below cell data based on adjacent cell data in excel using macro vba? 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 Excel - VBA复制部分行和插入下面 - Excel - VBA Copy Partial Row and Insert below Excel宏-如何根据特定的单元格值复制/拆分行 - Excel Macro - How to copy/split row based on specific cell value Excel宏可根据单元格值将一行中的选定单元格从一张纸复制到另一张纸 - Excel Macro to copy select cells from a row from one sheet to another based upon a cell value 将单元格复制并粘贴到VBA循环下面的行中 - Copy and Paste Cell into row below VBA Loop 从范围复制并附加到 VBA 宏下面 - Copy from range and append below VBA macro Excel VBA-根据单元格值复制和插入行 - Excel VBA- copy and insert row based on cell value VBA 复制一行的内容并根据单元格值将其相乘 - VBA copy contents of a row and multiply it based on a cell value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM