mercredi 1 avril 2015

Excel VBA isn't Validating integer values correctly for comparison

Basically I am trying to go through cells that have a value of less than 50 in a column(R:R)


Here is the code:



Sub Macro1()
'
' Macro1 Macro
'
'
Sheets("Pyxis Inventory 6North1 and 6No").Select
Cells(1).EntireRow.Copy (Sheets("Sheet1").Range("A1").EntireRow)
Cells(1).EntireRow.Copy (Sheets("Sheet2").Range("A1").EntireRow)

Dim val1, val2 As String
Dim i, j, x As Integer
Dim colCount As Integer
Dim daysUnused As Boolean
Dim daysVal As Integer
colCount = Sheets("Pyxis Inventory 6North1 and 6No").Range("A1").CurrentRegion.Rows.Count

daysUnused = IsEmpty(Sheets("Settings").Range("B2"))
If daysUnused = True Then
'do nothing yet

ElseIf daysUnused = False Then
daysVal = Sheets("Settings").Range("B2").Value
For x = 2 To colCount
If Cells(x, 18).Value <= daysVal Then
Cells(x, 18).EntireRow.Copy (Sheets("Sheet4").Range("A1").Offset(x, 0))
Cells(x, 18).EntireRow.Delete
End If
Next x
End If
End Sub


My problem is that it doesn't delete rows with numbers less than 50.


I have formatted the cells in the column 18 to be of number only as well.


What i want to do is basically sort, but instead of keeping the values I want to delete anything that is less than 50 or whatever the user enters for daysVal variable.


Thank you


Aucun commentaire:

Enregistrer un commentaire