Cut a cell from one column and paste to another.

Alrock

New Member
Joined
Sep 16, 2020
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
Hello everybody. I hop someone can help me with this. I work with a scale that continuously write the weights values to an excel sheet in one column, I need to cut the values that are out of the range of weight that I need from column B and paste them to column C, one after another and also I need after cut and paste each non desired value that the selected cell return to the next empty cell in column B to the scale continue writing . The range of weight is (>=193 and <=196) or (>192 and <197)

I was working whit this code because I was deleting the entire row with non desired values but now I need to keep them separated.

Sub test()
With ActiveSheet
.AutoFilterMode = False
With Range("B1", Range("B" & Rows.Count).End(xlUp))
.AutoFilter 1, ">196"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete Shift:=x1Up
End With
.AutoFilterMode = False
ActiveCell.Offset(rowOffset:=-1, columnOffset:=0).Activate
End With
End Sub


Thank you.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    26.4 KB · Views: 10

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Do you mean...?

Code:
Sub test()
    With ActiveSheet
        Application.ScreenUpdating = False
        .AutoFilterMode = False
        
        With .Range("B1", .Range("B" & Rows.Count).End(xlUp))
            .AutoFilter 1, "<193", xlOr, ">196"
            
            With .Offset(1)
                .Copy Range("C" & Rows.Count).End(xlUp)(2)
                .ClearContents
            
            
                On Error Resume Next
                ActiveSheet.AutoFilterMode = False
                .SpecialCells(4).Delete xlUp
                On Error GoTo 0
            End With
        
        End With
        
        Application.Goto .Range("B" & Rows.Count).End(xlUp)(2)
        
    End With
  
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Wow! very close. I need to keep all rejected values so It's possible to write the next rejected value below the previous and not overwrite?
 
Upvote 0
Where? This line
VBA Code:
.Copy Range("C" & Rows.Count).End(xlUp)(2)
"Pastes" the data in the next cell after the last cell with data in Column C and it sends the data in one go, it doesn't loop.
 
Upvote 0
Yes, that line copy the value out of the range to column C but the next value out of range overwrite the previous one, I need to keep them all.
 
Upvote 0
Try..

VBA Code:
Sub test()
    With ActiveSheet
        Application.ScreenUpdating = False
        .AutoFilterMode = False
      
        With .Range("B1", .Range("B" & Rows.Count).End(xlUp))
            .AutoFilter 1, "<193", xlOr, ">196"
          
            With .Offset(1)
                .Copy
                ActiveSheet.AutoFilterMode = False
                Range("C" & Rows.Count).End(xlUp)(2).PasteSpecial
            End With
          
            Application.CutCopyMode = False
          
            With .Offset(1)
                .AutoFilter 1, "<193", xlOr, ">196"
                .ClearContents
          
                On Error Resume Next
                .SpecialCells(4).Delete xlUp
                On Error GoTo 0
            End With
        End With
      
        ActiveSheet.AutoFilterMode = False
        Application.Goto .Range("B" & Rows.Count).End(xlUp)(2)
    End With

   
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Now it's cutting and copying number out of range to column C very well but it's deleting first cell in column B and moving the others cells one up.
 
Upvote 0
Try changing
Code:
            With .Offset(1)
                .AutoFilter 1, "<193", xlOr, ">196"
                .ClearContents
          
                On Error Resume Next
                .SpecialCells(4).Delete xlUp
                On Error GoTo 0
            End With
to
Code:
           .AutoFilter 1, "<193", xlOr, ">196"
           With .Offset(1)
                .ClearContents
          
                On Error Resume Next
                .SpecialCells(4).Delete xlUp
                On Error GoTo 0
            End With
 
Upvote 0

Forum statistics

Threads
1,215,014
Messages
6,122,697
Members
449,092
Latest member
snoom82

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