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.

N
O

P
Q
R
S
Item
Acct Amount

Expense
Freight
Pay
FUMID
14,906.56

267.35
(15,173.91)
FREIGHT

267.35
(15,173.91)
PAY

0.00
0.00
FUREG
16,367.38

316.33
(16,683.71)
FREIGHT

316.33
(16,683.71)
PAY

0.00
0.00
FUDSL
11,002.50

927.76
(11,930.26)
FUDYD
11,861.60

0.17
(11,861.77)
FREIGHT

927.93
(23,792.03)
PAY

0.00
0.00
FUDSL
11,002.50

608.08
(11,610.58)
FUDYD
11,877.30

0.16
(11,877.46)
FREIGHT

608.24
(23,488.04)
PAY

0.00
0.00

<tbody>
</tbody>

This how it should look after copy and transpose.
N
O
P
Q
R
S
Item
Acct Amount
Expense
Freight
Pay
FUMID
14,906.56
267.35
(15,173.91)
FREIGHT
267.35
267.35
(15,173.91)
PAY
(15,173.91)
0.00
0.00
FUREG
16,367.38
316.33
(16,683.71)
FREIGHT
316.33
316.33
(16,683.71)
PAY
(16,683.71)
0.00
0.00

<tbody>
</tbody>

Thank you in advance for your help!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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