[英]Is there an R function for finding a specific value and pasting it to the next cell to the right(next column same row number)
I have a report that contains values in two columns (B:C), when column B has a value, column C has an empty cell for the same row. 我有一个报告,其中包含两列(B:C)中的值,当B列具有值时,C列具有用于同一行的空单元格。
What I want to achieve is to create a macro to search for a specific value (ie "Desktop") in the column A and if it matches the search, copy/cut the value and paste it one cell to the next column but in the same row (that is meant to be blank), so all the values are aligned in one column (ie "Desktop" found in A1, then paste it to B1 without creating a new column). 我要实现的是创建一个宏以在A列中搜索特定值(即“桌面”),如果它与搜索匹配,请复制/剪切该值并将其粘贴到下一个列中的一个单元格中同一行(即为空白),因此所有值都在一列中对齐(即在A1中找到“桌面”,然后将其粘贴到B1中而不创建新列)。
Example: 例:
3 ways to get the job done. 完成工作的3种方法。
Dim cel As Range
'This will search for "Desktop" and copy it to the cell on the right.
For Each cel In Range("B2", Range("B" & Rows.Count).End(xlUp))
If cel.Value = "Desktop" Then
cel.Offset(, 1).Value = cel.Value
'The line below will remove "Desktop" from the cell if required
'cel.ClearContents
End If
Next cel
'Or
'This will search for "Desktop", insert a cell and shift to the right.
For Each cel In Range("B2", Range("B" & Rows.Count).End(xlUp))
If cel.Value = "Desktop" Then
cel.Insert Shift:=xlToRight
End If
Next cel
'Or
'This will search for any empty cell in Col C and copy the value from Col B.
For Each cel In Range("C2", Cells(Rows.Count, 3).End(xlUp))
If cel.Value = "" Then cel.Value = cel.Offset(, -1).Value
'The line below will remove "Desktop" from the cell if required
'cel.Offset(, -1).ClearContents
Next cel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.