For loop help

Herbalgiraffe

New Member
Joined
Feb 22, 2020
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hey guys, so long story short, I am trying to automate the process of updating item prices for my company, but for now I am just trying to create some sort of a For loop to do so. There are two worksheets involved, new prices to be input (Ws1), and the much larger current list of all items a customer may purchase, which holds the old pricing currently (Ws2). for sake of example Ws1 has maybe 200 items to be updated, and Ws2 has 1000. I need my loop to cycle through each item in Ws1, searching for a match in Ws2 so that upon identification, the new data is inputted on Ws2, which after updating is complete, gets uploaded back into a database. There are more steps for each found item, but for now I am just hoping to highlight found items on Ws2, and I will work on the rest from there. the other thing is that the amount of items in Ws1 and Ws2 can change depending on the customer, as not all customers buy all of our products. Is what I currently have somewhere close?

VBA Code:
    Dim Ws1 As Range
    Dim Ws2 As Range
    Dim finalrow As Integer
    Dim i As Integer
    
    finalrow = Cells(Rows.Count, 1).End(xlUp).Row
    Set Ws2 = Range(Worksheets(Sheet2).Range("A1"), finalrow)
    Set Ws1 = Range(Worksheets(Sheet1).Range("A1"), finalrow)
        
    With ActiveSheet
         For i = 2 To finalrow
              If .Cells(Ws1) Like .Cells(Ws2) Then
              cell.Interior.ColorIndex = 3

              End If
         Next
    End With

End Sub
 
My apologies for not being more clear. The end goal would be to have the value of fn.Offset(1, 4) to equal the result of that formula, but since it is within the loop, I would need A2 to change to whatever row the loop is executing on. Maybe there is a way to accomplish it without the formula at all, im not entirely sure, but however I could possibly accomplish that function so that I can pull that item's price from Ws1 into Ws2, thats the goal regardless of how I get there.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
If I read it right then this should put the price where you want it.

VBA Code:
fn.Offset(1, 4).Value = c.Offset(, 2),Value
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,941
Members
449,094
Latest member
teemeren

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