Copy Cells above Zero and Transpose

sarah1024

New Member
Joined
Oct 15, 2018
Messages
7
Hello,
I’m trying to copy cells above value 0.00 in column R and S and transpose them on to column O in the same row.
Following is the snapshot of the sheet I am working with, cells in Red need to be copied and transposed on to column O. This needs to be repeated until the last populated line in column R.
[TABLE="width: 579"]
<tbody>[TR]
[TD]
N
[/TD]
[TD]O
[/TD]
[TD]
[/TD]
[TD]P
[/TD]
[TD]Q
[/TD]
[TD]R
[/TD]
[TD]S
[/TD]
[/TR]
[TR]
[TD]Item
[/TD]
[TD]Acct Amount
[/TD]
[TD]
[/TD]
[TD]Expense
[/TD]
[TD][/TD]
[TD]Freight
[/TD]
[TD]Pay
[/TD]
[/TR]
[TR]
[TD]FUMID
[/TD]
[TD]14,906.56
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]267.35
[/TD]
[TD](15,173.91)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]267.35
[/TD]
[TD](15,173.91)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
[TR]
[TD]FUREG
[/TD]
[TD]16,367.38
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]316.33
[/TD]
[TD](16,683.71)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]316.33
[/TD]
[TD](16,683.71)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
[TR]
[TD]FUDSL
[/TD]
[TD]11,002.50
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]927.76
[/TD]
[TD](11,930.26)
[/TD]
[/TR]
[TR]
[TD]FUDYD
[/TD]
[TD]11,861.60
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.17
[/TD]
[TD](11,861.77)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]927.93
[/TD]
[TD](23,792.03)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
[TR]
[TD]FUDSL
[/TD]
[TD]11,002.50
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]608.08
[/TD]
[TD](11,610.58)
[/TD]
[/TR]
[TR]
[TD]FUDYD
[/TD]
[TD]11,877.30
[/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.16
[/TD]
[TD](11,877.46)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]608.24
[/TD]
[TD](23,488.04)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
</tbody>[/TABLE]

This how it should look after copy and transpose.
[TABLE="width: 580"]
<tbody>[TR]
[TD]N
[/TD]
[TD]O
[/TD]
[TD]P
[/TD]
[TD]Q
[/TD]
[TD]R
[/TD]
[TD]S
[/TD]
[/TR]
[TR]
[TD]Item
[/TD]
[TD]Acct Amount
[/TD]
[TD]Expense
[/TD]
[TD][/TD]
[TD]Freight
[/TD]
[TD]Pay
[/TD]
[/TR]
[TR]
[TD]FUMID
[/TD]
[TD]14,906.56
[/TD]
[TD][/TD]
[TD][/TD]
[TD]267.35
[/TD]
[TD](15,173.91)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD]267.35
[/TD]
[TD][/TD]
[TD][/TD]
[TD]267.35
[/TD]
[TD](15,173.91)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD](15,173.91)
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
[TR]
[TD]FUREG
[/TD]
[TD]16,367.38
[/TD]
[TD][/TD]
[TD][/TD]
[TD]316.33
[/TD]
[TD](16,683.71)
[/TD]
[/TR]
[TR]
[TD]FREIGHT
[/TD]
[TD]316.33
[/TD]
[TD][/TD]
[TD][/TD]
[TD]316.33
[/TD]
[TD](16,683.71)
[/TD]
[/TR]
[TR]
[TD]PAY
[/TD]
[TD](16,683.71)
[/TD]
[TD][/TD]
[TD][/TD]
[TD]0.00
[/TD]
[TD]0.00
[/TD]
[/TR]
</tbody>[/TABLE]

Thank you in advance for your help!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi, assuming you want this to be done with a macro, you can try this:

Code:
Dim i As Integer
Dim lrow As Long

lrow = Cells.Find(What:="*", after:=Range("R1"), lookat:=xlPart, LookIn:=xlFormulas, searchorder:=xlByRows, searchdirection:=xlPrevious, MatchCase:=False).Row

For i = 1 To lrow
    If Range("R" & i).Value = 0 Then
        Range("O" & i).Offset(-1).Value = Range("R" & i).Offset(-1).Value
        Range("O" & i).Value = Range("R" & i).Offset(-1, 1).Value
    End If
Next
 
Upvote 0
Hello Kenny,

Thank you for your quick response, but am getting Run-time error '1004'

For i = 1 To lrow If Range("R" & i).Value = 0 Then
Range("O" & i).Offset(-1).Value = Range("R" & i).Offset(-1).Value
Range("O" & i).Value = Range("R" & i).Offset(-1, 1).Value
End If
Next

End Sub
 
Upvote 0
Another option
Code:
Sub CopyTrans2()
   Dim Rng As Range
   For Each Rng In Range("O:O").SpecialCells(xlBlanks).Areas
      Rng.Value = Application.Transpose(Rng.Offset(, 3).Resize(, 2).Value)
   Next Rng
End Sub
 
Upvote 0
Hello Kenny,

Thank you for your quick response, but am getting Run-time error '1004'

For i = 1 To lrow If Range("R" & i).Value = 0 Then
Range("O" & i).Offset(-1).Value = Range("R" & i).Offset(-1).Value
Range("O" & i).Value = Range("R" & i).Offset(-1, 1).Value
End If
Next

End Sub

Try adding the sheet to each instance of range.

So when setting lrow declare which sheet it is, for example: Sheets(1).Cells.Find etc.

Sheets(1).Range("O" & i) etc.
 
Upvote 0
Another option
Code:
Sub CopyTrans2()
   Dim Rng As Range
   For Each Rng In Range("O:O").SpecialCells(xlBlanks).Areas
      Rng.Value = Application.Transpose(Rng.Offset(, 3).Resize(, 2).Value)
   Next Rng
End Sub


Thank you! this worked perfectly!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top