ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Finding Matching Records in a Column (https://www.excelbanter.com/excel-programming/308136-finding-matching-records-column.html)

Archie[_3_]

Finding Matching Records in a Column
 
Hello,
I wanted to post because I'm a beginner with VBA.
I'm writing a program now; I have an active worksheet
(pls. refer to below) and program's objective is to be
able to find in Column A all matching records that contain
cell value "Job ID", copy its corresponding data values
(248, 249, etc.) from column B to rows in a new worksheet.
It's supposed to filter all Job IDs based on the size and
cell records of Column A. Reiteratively, once the program
is done with "Job ID", it will go to the next
(Workstation) and find all occurrences of its value and do
the same thing.

Job ID 248
Workstation ANSOS 1
Source D:

Job ID 249
Workstation ANSOS 2
Source E:

My code is below and it is really cluttered, but hoping
someone from this forum can shed some light, offer some
advice/critique.

Sub GetJobID()
Dim IRange As Range
Dim ORange As Range
Dim CRange As Range
Dim xSheet2 As Sheet2
Dim FinalRow As Range

'Find the size of today's backup log
FinalRow = xSheet2.Cells(65536, 1).End(x1Up).Row
NextCol = xSheet2.Cells(1, 255).End(x1ToLeft).Column+2

'Setup Output Range with JobID
Sheet2.Cells(1, NextCol).Value = Range
("ActiveCell").Value
Sheet2.Cells(2, NextCol).Value = "Job ID"
Set CRange = Cells(1, NextCol).Resize(2, 1)

'Setup Output Range to another column.
Range("B1").Copy = Cells(1, NextCol + 2)
Set ORange = Cells(1, NextCol + 2)

'Define the input range
Set IRange = Range("A1").Resize(FinalRow, NextCol - 2)

'Do the Advanced Filter to get unique JobID
IRange.AdvancedFilter Action = xlFilterCopy,_
CriteriaRange = CRange, CopyToRange = ORange, _
Unique = True
End Sub

The program stops at FinalRow; says "Run-Time Error 91:
Object variable or With blok variable not set."

Any and all help is much appreciated! Thanks!


All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com