我有一个问题。我需要在MS-Excel中把数据从一列移动到另一列的替代行中。
为了使它更容易,请看 截图. 它显示了我需要的确切输出。
如果可能的话,请提供解决方案,通过 公式 而不是VBA代码。
非常感谢您的支持。
祝贺你
对于截图中的设置,使用以下公式。
[G2] =IF(MOD(ROW(),2)=0,C3,"")
[H2] =IF(MOD(ROW(),2)=0,C2,"")
如果你真的想重新排列(移动)数据,这里有一个VBA解决方案。
Option Explicit
Sub MoveData()
Const wsName As String = "Sheet1" ' Worksheet Name
Const srcRange As String = "C2:C11" ' Source Range Address
Const tgtRange As String = "B2:C11" ' Target Range Address
Dim ws As Worksheet ' Worksheet
Dim Source As Variant ' Source Array
Dim Target As Variant ' Target Array
Dim i As Long ' Source/Target Array Element (Row) Counter
' Define worksheet.
Set ws = ThisWorkbook.Worksheets(wsName)
' Copy Source Range to Source Array.
Source = ws.Range(srcRange)
' Copy values from Source Array to Target Array.
ReDim Target(1 To UBound(Source), 1 To 2)
For i = 1 To UBound(Target) Step 2
Target(i, 1) = Source(i + 1, 1)
Target(i, 2) = Source(i, 1)
Next i
'-Copy values from Target Array to Target Range.
ws.Range(tgtRange) = Target
End Sub