Hello,
I currently have an Excel workbook with three worksheets. The first contains all the variables and data. The second is coded in VBA to require a user input of a number greater than or equal to 0. When the user inputs a number they then push a command button and it pulls data that is associated with the user input number. The third worksheet is the exact same excpet it requires a user input of a number less than 0. What I am trying to do is consolidate the codes so that the user input can be greater than, equal to, or less than 0. I tried using if else but it just creates errors. Any suggestions as to how I might go about this?
<strike></strike>
<strike></strike>
I currently have an Excel workbook with three worksheets. The first contains all the variables and data. The second is coded in VBA to require a user input of a number greater than or equal to 0. When the user inputs a number they then push a command button and it pulls data that is associated with the user input number. The third worksheet is the exact same excpet it requires a user input of a number less than 0. What I am trying to do is consolidate the codes so that the user input can be greater than, equal to, or less than 0. I tried using if else but it just creates errors. Any suggestions as to how I might go about this?
Code:
Sub Rectangle1_Click()
Dim i As Integer, n As Integer
n = 3
For i = 504 To [M65536].End(3).Row
If D2.Cells(i, 27).Value >= 3 Then
DashBoard.Cells(n, 1).Value = D2.Cells(i, 3).Value
DashBoard.Cells(n, 2).Value = D2.Cells(i, 27).Value
n = n + 1
End If
Next
End Sub
Code:
[FONT=Verdana]
Sub tt()
On Error Resume Next
er = Sheets("D2").Range("AA65536").End(xlUp).Row
ec = Range("IV1").End(xlToLeft).Column
r = 3
Range("A3:IV65536").ClearContents
For i = 504 To er
a = Sheets("D2").Cells(i, "AA")
If WorksheetFunction.IsErr(a) Then a = 0
If a >= Cells(2, 1).Value Then
For j = 2 To ec
f = Cells(1, j)
Cells(r, j) = Sheets("D2").Cells(i, f)
Next j
r = r + 1
End If
Next i
End Sub[/FONT]
Code:
[FONT=Verdana]Sub xx()
On Error Resume Next
er = Sheets("D2").Range("AA65536").End(xlUp).Row
ec = Range("IV1").End(xlToLeft).Column
r = 3
Range("A3:IV65536").ClearContents
For i = 504 To er
a = Sheets("D2").Cells(i, "AA")
If WorksheetFunction.IsErr(a) Then a = 0
If a <= Cells(2, 1).Value Then
For j = 2 To ec
f = Cells(1, j)
Cells(r, j) = Sheets("D2").Cells(i, f)
Next j
r = r + 1
End If
Next i
End Sub [/FONT]
<strike></strike>