Comparing Items in a worksheet via VBA

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
New to VBA and i'm having issues figuring out how to compare data in a spreadsheet.


I have data in beginning in column A and ending in E. I want to test using a Range A1:E100. With the data from A:A being compared to Cell G5 (Constant) on the same sheet. If the value in A:A matches G5 then copy the row and paste in J5.

Please Help!!!!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
give this a try

Code:
Sub test()
    Dim rng As Range
    Dim cl As Range
 
    Set rng = Range("A1:A100")
 
    For Each cl In rng
        If (cl.Value = Range("G5")) Then
            Range(Cells(cl.Row, 1), Cells(cl.Row, 5)).Copy Range("J5")
        End If
    Next cl
End Sub
 
Upvote 0
Thanks a million D_boggus. I apologize i said that "G5" remained constant. Well can you show me a change to the code so that A:A references G:G (not constant) "J5" should also change as more records are copied. .

:)
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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