Consolidating Three Codes into One For Pulling Data-VBA

sopa12

New Member
Joined
Mar 30, 2019
Messages
4
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?

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>

<strike></strike>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,223,887
Messages
6,175,199
Members
452,617
Latest member
Narendra Babu D

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