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

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88
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
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
If you are always looking for numerical values try
VBA Code:
If (Cells(i, "E").Value) = Val(Dollar_Move) Then
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88

ADVERTISEMENT

Fluff, just one more quick question. This works great with an = sign but doesn't with a < or a > any thoughts?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
Should work quite happily with both. Are the values in col E all numbers?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,755
Office Version
  1. 365
Platform
  1. Windows
In that case this should work.
VBA Code:
        If (Cells(i, "E").Value) < Val(Dollar_Move) Then
 

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88
I pasted that then entered 20000 and just got a blank line copied and pasted.
 

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,239
Messages
5,595,002
Members
413,958
Latest member
SBM

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
Top