Cutting and Pasting individual cells that meet criteria to same row of different column

tdepke1

New Member
Joined
Oct 7, 2021
Messages
3
Office Version
  1. 2013
Platform
  1. Windows
I'm a n00b and I've been searching the forums and the closest thing I can find to my problem was addressed here: Simple Macro to cut and paste based on cell value

I'm trying to have any cells in column M that are greater than 0 be cut and paste into a column 3 columns to the right of the original in the same row in the same worksheet. This code below was from the original forum

VBA Code:
Sub atest()
Dim LR As Long, i As Long
With Sheets("All")
    LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("C" & i)
            If .Value Like "*Time*" Then .EntireRow.Cut Destination:=Sheets("All Time").Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
        End With
    Next i
End With
End Sub

The code I've got looks like this:

VBA Code:
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("M" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("M" & i)
            If .Value > 0 Then .Cut Destination:=Sheets("Sheet1").Range("M" & Rows.Count).End(xlUp).Offset(0, 3)
            ActiveSheet.Paste
        End With
    Next i
End With


It returns an error saying:

Run-time error '1004'
Paste method of Worksheet class failed

Running the macro currently only cuts the first value greater than 0 in Column M and pastes it into Column P (good!), but into the last row with a value greater than 0 from Column M (BAD). So I'm needing
1. it to do this for all cells in Column M greater than 0
2. paste it in the same row of Column P
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to MrExcel.
Try it like
VBA Code:
Dim LR As Long, i As Long
With Sheets("Sheet1")
    LR = .Range("M" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("M" & i)
            If .Value > 0 Then .Cut Destination:=.Offset(0, 3)
        End With
    Next i
End With
 
Upvote 0
Solution
Thanks for the quick reply! That solved that question!

I have a follow-up question that is very similar. If I'm trying to have any cells in a separate column (Column B) that contain the word "stipend" then I'd like to have the cell 3 columns to the right have "Work" and the cell one column to the right of that (4 columns to the right of Column B) have "Stipend" in it. Here is what I currently have:


VBA Code:
Dim LR3 As Long, i3 As Long
With Sheets("Sheet1")
    LR3 = .Range("B" & Rows.Count).End(xlUp).Row
    For i3 = 1 To LR3
        With .Range("B" & i3)
            If .Value = "*stipend*" Then .Offset(0, 3).Select
    ActiveCell.FormulaR1C1 = "Work": .Offset(0, 1).Select  ActiveCell.FormulaR1C1 = "Stipend"
    
        End With
    Next i3
End With

The part after the "Work": is what I'm having trouble with.

Thanks so much for your help!
 
Upvote 0
How about
VBA Code:
Dim LR3 As Long, i3 As Long
With Sheets("Sheet1")
    LR3 = .Range("B" & Rows.Count).End(xlUp).Row
    For i3 = 1 To LR3
        With .Range("B" & i3)
            If .Value Like "*stipend*" Then
               .Offset(, 3).Resize(, 2).Value = Array("Work", "Stipend")
            End If
        End With
    Next i3
End With
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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