Loop with Offsets

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, done quite a bit of research and I cannot quite figure this out..

This script should be
* searching for "PartNum" once found
* moves down 2 cells
* Copies the value on the new active cell
* searches for that value in worksheet "export"
* once found copies the value offset 24 cells to the right
* returns to workbook "quote"
* Finds "Leadtime"
* move down 2 cells and pastes the value

The part i'm stuck on, I didn't write this correctly to loop as i would like, how can i accurately loop 1 row lower each time? Is there any way I can add so it ignores if a part is not found instead of erroring out?


VBA Code:
'Find PartNum
Worksheets("Quote").Activate
Cells.Find(What:="PartNum").Offset(2, 0).Select

'Copy/search part Num

   Dim str1 As String
    Dim Cntr As Integer
    Cntr = 0
    Do While Cntr <= 650

      Cntr = Cntr + 1
      str1 = ActiveCell.Value
      Selection.Copy

      Worksheets("Export").Activate
      ActiveCell.Select
      Cells.Find(What:=str1, After:=ActiveCell, LookIn:= _
        xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
        xlNext, MatchCase:=False, SearchFormat:=False).Activate
      Cells.FindNext(After:=ActiveCell).Activate
      ActiveCell.Offset(0, 24).Range("A1").Select
      Selection.Copy

      Worksheets("Quote").Activate
     
     
'Find PartNum
Cells.Find(What:="Leadtime").Offset(2, 0).Select
      Selection.PasteSpecial Paste:=xlPasteValues
     
    Loop
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Just so clarify, this is all within the same workbook starting in sheet "Quote" and searching within "Export" before returning to "Quote"
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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