copy and paste doesn't work when cell value is a number

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
Ive seen some similar things here but nothing quite like this . The following code below works fine as long as I have an alpha value in the range I'm looking for but will not do the same if i have a numeric value.
What I am trying to do is to copy and paste a line if the numeric value that is entered by the user is found in the column. If I change one of the values to be something alpha like dog it will work. However if I change dog back to 1234 it will not copy and paste the line. To make it more interesting, if I replace the = with a < or a > it will copy the header but not the row with the value in it. Any thoughts?

Application.ScreenUpdating = False


Dim Dollar_Move As Variant

'Opening Dialog
Dollar_Move = InputBox("Enter the lowest dollar amount to be move (This will move the entered amount and everything larger")
'
MsgBox Dollar_Move & " $$$ DOLLARS AND OVERE IS BEING MOVED TO THE REPORT PAGE"


Sheets("Build_Page").Select

Last = Cells(Rows.Count, "E").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "E").Value) = Dollar_Move Then

Cells(i, "A").Select


Cells(i, "A").EntireRow.Copy




Sheets("Report").Select
Range("a2:I5000").Select


Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.PasteSpecial Paste:=xlPasteValues
ActiveCell.PasteSpecial Paste:=xlPasteFormats


End If






Next i
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
If you are always looking for numerical values try
VBA Code:
If (Cells(i, "E").Value) = Val(Dollar_Move) Then
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Fluff, just one more quick question. This works great with an = sign but doesn't with a < or a > any thoughts?
 
Upvote 0
Should work quite happily with both. Are the values in col E all numbers?
 
Upvote 0
In that case this should work.
VBA Code:
        If (Cells(i, "E").Value) < Val(Dollar_Move) Then
 
Upvote 0
I pasted that then entered 20000 and just got a blank line copied and pasted.
 
Upvote 0
what is baffling is if I use the < it copies and pastes a blank line but if I use the > it copies and pastes the header of the destination page. If I use the = it works perfectly
 
Upvote 0

Forum statistics

Threads
1,214,548
Messages
6,120,146
Members
448,948
Latest member
spamiki

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