Copy and paste by condition. Without selecting the particular cell

ZOL

New Member
Joined
Aug 15, 2011
Messages
21
I want to the cut and paste to be done by not selecting the cells or activating it. Eg, .select or .activate. It is possible to be done? My code below shows me error on object does not support property or method. Why is this so?

Code:
Sub test()
With Sheets("Sheet1")

A = 5
B = 4
        NextRow = Application.WorksheetFunction.CountA(.Range("A:A")) + 1
    
        Set r = .Range(.Cells(2, 1), .Cells(NextRow, 1))
    
        For n = 2 To r.Rows.Count
        If A >= B Then
            If .Cells(n, 2).Value = "" Then
                
                    
                    .Range("A" & "2" & ":K" & "n-1").Cut
                End If
            End If
        Next n
        
        NextRow = Application.WorksheetFunction.CountA(.Range("A:A")) + 1
    
        Set r = .Range(.Cells(2, 1), .Cells(NextRow, 1))
         For n = 2 To r.Rows.Count
         If A >= B Then
            If .Cells(n, 13).Value = "" Then
                
                    RowCount = .Cells(n, 2).Row
                    .Range("M" & RowCount).Paste
                End If
            End If
        Next n

End With

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
This is the only blatant error I found:
Code:
                .Range("A2:K" & n - 1).Cut

But if you describe verbally what you're doing, I'm pretty sure it can be done without the looping, too.
 
Upvote 0
It will have to check for the empty cell then minus one row up.
They didnt direct me into the .Range("A2:K" & n - 1).Cut when the cell is empty. what did i does wrongly?
 
Last edited:
Upvote 0
Can you describe verbally your goal without referring to macros? Tell me what you're trying to do.
 
Upvote 0
My goal is to check for the last row... eg.. last row is 4. then it will cut frm the range A2 to the K4
 
Upvote 0
When i change the code to the below one, it worked for me. why is it so?
Code:
Set r = .Range(.Cells([COLOR="Red"]1[/COLOR], 1), .Cells(NextRow, 1))
 
Upvote 0
I dont' know, I still don't know enough about what you're doing. Are you saying basically... "I want to copy find the last row of data, for example row 4, then cut from A1:K4 and paste it ....where?"

If all you want to do is find the last row with data, that's easy:
Code:
Dim LR

LR = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:K" & LR).Cut

It looks like you're trying to paste in column M. If you want to find the next empty cell in column M as the starting point, it's the same approach:

Code:
Dim LR as Long, NR as Long

LR = Range("A" & Rows.Count).End(xlUp).Row
NR = Range("M" & Rows.Count).End(xlUp).Row + 1 

Range("A1:K" & LR).Cut Range("M" & NR)
 
Upvote 0
Yup, that's what i want to do.. Do you know why when I tried to change the code above to 1 and it works?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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