I have 2 Excel Files
Tracker
**Grp** **Current Status** **Prior Status** **Any Changes**
grp1 Implementation Approved Change
grp2 Approved Approved No Change
grp3 Doc Recd Doc Recd No Change
grp4 Implementation Approved Change
Inventory
**Grp** **Current Status** **Col02**
grp1 Approved 789
grp2 Approved 123
grp3 Doc Recd 456
grp4 Approved 000
I am very new to VBA , I am not sure how to write a query , so approaching the community for help .
In Trackers file if Grp has different values in status and Prior Status then Any Changes will be considered as change.
If Current Status & Prior Status are same it will be considered as No Change
for below example grp1 & grp4 Current Status has changed from Prior Status
I just want code :
That Checks Change in Any Changes column "If Change"
Then grp1 & grp4 Current Status from Tracker file should be updated in Inventory file Current Status column based on the Group Name.
Note: Sometimes there might be extra spaces between the both file grp field.
I do this manually and update records from Tracker to Inventory everyday.
VBA Code should activate respective files and columns and change values.
Code i tried didn't work attaching below
Sub Lookup()
Dim rngeĀ asĀ Range
Dim cl As Range
Workbooks("Trackers 040620 PM.xlsx").Activate
Worksheets("Central").Activate
lastrow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lastrow
If Range("g" & i).Value = "Change" Then
srchval = Trim(Range("d" & i).Value)
chgval = Trim(Range("e" & i).Value)
Workbooks("Interim Inventory Tracker - All States 040620 v1.xlsx").Activate
Sheets("Main Data input").Activate
get_row_number = Workbooks("Interim Inventory Tracker - All States 040620 v1.xlsx"). _
Sheets("Main Data input").Range("D:D").Find( _
What:=srchval, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True _
).Row
If get_row_number = "" Then
'do nothing
Else
Workbooks("Interim Inventory Tracker - All States 040620 v1.xlsx").Activate
Sheets("Main Data input").Range("H" & get_row_number).Value = chgval
chgval = ""
End If
Workbooks("Trackers 040620 PM.xlsx").Activate
Worksheets("Central").Activate
End If
Next i
End Sub
Try
Option Explicit
Sub Lookup()
Const WB_TRACKER = "Trackers 040620 PM.xlsx"
Const WB_INVENTORY = "Interim Inventory Tracker - All States 040620 v1.xlsx"
Dim wbTracker As Workbook, wsTracker As Worksheet
Dim wbInventory As Workbook, wsInventory As Worksheet
Dim rng As Range
Dim iLastRow As Long, iRow As Long, count As Long
Dim srchval As String, chgval As String
Set wbTracker = Workbooks(WB_TRACKER)
Set wsTracker = wbTracker.Sheets("Central")
Set wbInventory = Workbooks(WB_INVENTORY)
Set wsInventory = wbInventory.Sheets("Main Data input")
iLastRow = wsTracker.Range("G" & Rows.count).End(xlUp).Row
count = 0
For iRow = 2 To iLastRow
If wsTracker.Range("G" & iRow).Value = "Change" Then
srchval = Trim(wsTracker.Range("D" & iRow).Value)
chgval = Trim(wsTracker.Range("E" & iRow).Value)
Set rng = wsInventory.Range("D:D").Find( _
What:=srchval, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=True)
If rng Is Nothing Then
'do nothing
Else
wsInventory.Range("H" & rng.Row) = chgval
count = count + 1
End If
End If
Next
MsgBox iLastRow - 1 & " rows scanned on " & wsTracker.Name & vbCr & _
count & " rows updated on " & wsInventory.Name, vbInformation
End Sub
Related
Im copying data from workbook to another with the code below. I want to copy customer details and the products with values > 0. Currently my macro is copying all the product columns in a row.
Any ideas how to solve this?
Sub copysales()
Dim wb As New Workbook, rowToCopy As Integer
Dim lRow As Integer, nRow As Integer, rowno As Integer, colno As Integer
Set wb = Workbooks("Product.xlsx")
lRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
nRow = wb.Sheets("Sales").Cells(Rows.Count, 1).End(xlUp).Row + 1
rowToCopy = nRow
Application.ScreenUpdating = False
For rowno = 2 To lRow
If (ThisWorkbook.Sheets("Sheet1").Range("Q" & rowno) = "Close (won)" Or ThisWorkbook.Sheets("Sheet1").Range("Q" & rowno) = "Close (part-won)") _
And ThisWorkbook.Sheets("Sheet1").Range("K" & rowno) > 0 And ThisWorkbook.Sheets("Sheet1").Range("T" & rowno) = Date - 1 Then
For colno = 72 To 79
If ThisWorkbook.Sheets("Sheet1").Cells(rowno, colno) <> "" Then
ThisWorkbook.Sheets("Sheet1").Range("K" & rowno).Copy wb.Sheets("Sales").Range("A" & rowToCopy) 'To copy sales person name
ThisWorkbook.Sheets("Sheet1").Range("D" & rowno).Copy wb.Sheets("Sales").Range("B" & rowToCopy) 'To copy customer name
ThisWorkbook.Sheets("Sheet1").Range("E" & rowno).Copy wb.Sheets("Sales").Range("C" & rowToCopy) 'To copy legal number
ThisWorkbook.Sheets("Sheet1").Range("Q" & rowno).Copy wb.Sheets("Sales").Range("F" & rowToCopy) 'To copy status
ThisWorkbook.Sheets("Sheet1").Range("P" & rowno).Copy wb.Sheets("Sales").Range("G" & rowToCopy) 'To copy sales type
ThisWorkbook.Sheets("Sheet1").Cells(1, colno).Copy wb.Sheets("Sales").Range("H" & rowToCopy) 'To copy product name
ThisWorkbook.Sheets("Sheet1").Cells(rowno, colno).Copy
wb.Sheets("Sales").Range("E" & rowToCopy).PasteSpecial xlPasteValues 'To copy product value
rowToCopy = rowToCopy + 1
End If
Next
End If
Next
End With
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
To copy just the cells where product value is > 0, check for that criteria where you currently check that the product value cell has content (ThisWorkbook.Sheets("Sheet1").Cells(rowno, colno) <> "")
Something perhaps like the following. Reformatted the code and made some changes to improve readability.
Option Explicit
Sub copysales()
Dim rowToCopy As Integer
Dim lRow As Integer, nRow As Integer, rowno As Integer, colno As Integer
'Repeatedly calling the lengthy expression 'ThisWorkbook.Sheets("Sheet1")' to reference Sheet1
'makes the code harder to read and can negatively impact speed if there is a large number of rows
Dim wrkSheet1 As Worksheet
Set wrkSheet1 = ThisWorkbook.Sheets("Sheet1")
'Repeatedly calling the lengthy expression 'wb.Sheets("Sales")' to reference the 'Sales' worksheet
'makes the code harder to read and can negatively impact speed if there is a large number of rows
Dim wrkSheetSales As Worksheet
Set wrkSheetSales = Workbooks("Product.xlsx").Sheets("Sales")
lRow = wrkSheet1.Cells(Rows.Count, 1).End(xlUp).Row
nRow = wrkSheetSales.Cells(Rows.Count, 1).End(xlUp).Row + 1
rowToCopy = nRow
Application.ScreenUpdating = False
For rowno = 2 To lRow
If IsRowOfInterest(wrkSheet1, rowno) Then
For colno = 72 To 79
If HasValueOfInterest(wrkSheet1.Cells(rowno, colno)) Then
wrkSheet1.Range("K" & rowno).Copy wrkSheetSales.Range("A" & rowToCopy) 'To copy sales person name
wrkSheet1.Range("D" & rowno).Copy wrkSheetSales.Range("B" & rowToCopy) 'To copy customer name
wrkSheet1.Range("E" & rowno).Copy wrkSheetSales.Range("C" & rowToCopy) 'To copy legal number
wrkSheet1.Range("Q" & rowno).Copy wrkSheetSales.Range("F" & rowToCopy) 'To copy status
wrkSheet1.Range("P" & rowno).Copy wrkSheetSales.Range("G" & rowToCopy) 'To copy sales type
wrkSheet1.Cells(1, colno).Copy wrkSheetSales.Range("H" & rowToCopy) 'To copy product name
wrkSheet1.Cells(rowno, colno).Copy
wrkSheetSales.Range("E" & rowToCopy).PasteSpecial xlPasteValues 'To copy product value
rowToCopy = rowToCopy + 1
End If
Next
End If
Next
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
'This function checks the criteria for copying the data
Private Function HasValueOfInterest(ByVal valueRange As Range) As Boolean
HasValueOfInterest = False
On Error GoTo ErrorExit
'Not sure how the value is formatted and stored in Sheet1 (String or Number).
'The error handling (On Error GoTo ErrorExit) ensures False is returned when CDbl() operates on a cell value that is not a number
HasValueOfInterest = valueRange.Value <> "" And CDbl(valueRange.Value2) > 0#
Exit Function
ErrorExit:
End Function
'Added to improve readability of the 'copysales' subroutine
Private Function IsRowOfInterest(ByVal wrkSheet As Worksheet, ByVal rowno As Integer) As Boolean
IsRowOfInterest = _
(wrkSheet.Range("Q" & rowno) = "Close (won)" _
Or wrkSheet.Range("Q" & rowno) = "Close (part-won)") _
And wrkSheet.Range("K" & rowno) > 0 _
And wrkSheet.Range("T" & rowno) = Date - 1
End Function
I hope your weeks are going well.
Currently writing a data entry from in a VBA user form,
It will be using an array of checkboxes to select size which then fills a row with the other data provided when that checkbox is ticked.
I'm currently running into an issue where I don't know what code to run to have the function delete its previous data when the checkbox is unticked.
Private Sub CheckBox0k_Click()
'''Input
Dim ws As Worksheet
Dim LastRow As Long, RowInsert As Long
Set ws = ThisWorkbook.Worksheets("stock")
With ws
LastRow = .Cells(Rows.Count, "A").End(xlUp).row
RowInsert = .Range("A1:A" & LastRow).Find("*", .Cells(LastRow, "A"), xlValues, , , xlPrevious).row
RowInsert = RowInsert + 1
'add the uk size input code here
'''Checkbox based search
''Start
If Me.CheckBox0k.Value = True Then
''''This has to match the number of rows input below
.Cells(RowInsert, "A").Resize(1, 8).Value = Array( _
Me.txtDate.Text, _
Me.textboxparentsku.Text, _
Me.textboxsku.Text, _
Me.comboboxbrand.Text, _
Me.comboboxclosure.Text, _
Me.comboboxgender.Text, _
Me.comboboxmaterial.Text, _
Me.comboboxmodel.Text _
)
ws.Range("I" & RowInsert).Value = CheckBox0k.Caption
'This is the code I'm having issues with
ElseIf CheckBox0k.Value = False Then
.Cells(RowInsert, "A").Resize(1, 8).Value = ws.Range("I" & RowInsert).Value = ""
End If
''Finish
Set ws = Nothing
End With
End Sub
A picture of the current UI with the multiple checkboxes
In order to help, we would need to know more about the process. I men, do you need clearing the last 8 entries (columns)? If so, the working solution should be something like
.Cells(RowInsert, "A").Resize(1, - 9).Value = ""
But your code must check if there are data in the first columns of the row to be processed and warn...
Ok I have sorted it I made a new rule called RowInvert = RowInsert - 1 and put that into FaneDuru's code:
ElseIf Me.CheckBox0k.Value = False Then .Cells(RowInvert, "A").Resize(1, 9).Value = ""
This is my first time using VBA and macros in excel, or excel really for that matter. I appreciate any help or insight that you could give me, ranging from what functions to loops can help me succeed in this task
I am trying to get this workbook set up from this:
Sample Work Book
I get a list that has to be reordered in order to import into another system. My task list is as follows for a macro:
Names and companies have to be merged into one, if there is a different name of a person, that must be concatenated. There will not be two different companies per company header.
Every File ID per company must be concatenated
Individual fees must be replaced with total fee per company.
Sorted by internal ID #, A-Z
Only one header on the new sheet
To look like this:
Target Work Book
My code below runs this: Current Progress
Sub format()
Application.ScreenUpdating = False
'This is the setup to get rid of unnecessary cells'
Dim rCell As Range
Dim cRow As Long, LastRow As Long
LastRow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
'''Delete Merged Cells'''
With Worksheets("Sheet1").Range("A1", Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp))
Do
Set c = .Find(What:="*Company Name:*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
cRow = c.Row
c.EntireRow.Delete
End If
Loop While Not c Is Nothing And cRow < LastRow
End With
'''Delete Headings'''
With Worksheets("Sheet1").Range("A1", Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp))
Do
Set c = .Find(What:="*File #*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
cRow = c.Row
c.EntireRow.Delete
End If
Loop While Not c Is Nothing And cRow < LastRow
End With
''' Delete Sub Total"""
With Worksheets("Sheet1").Range("A1", Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp))
Do
Set c = .Find(What:="*Sub Total:*", After:=[A1], LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not c Is Nothing Then
cRow = c.Row
c.EntireRow.Delete
End If
Loop While Not c Is Nothing And cRow < LastRow
End With
End Sub
Again, I appreciate any help on this matter. Thank you!
There are a lot of ways to loop through the cells.
I picked column D with the company name as it didn't have too much clutter.
It's usually good to find the last row, to not loop through cells that we don't need. THere is a lot of ways for doing so as well. Today we'll go with Range("D" & .Rows.Count).End(xlUp).Row.
For the loop, we can use the For next approach, example:
For i = 1 To Sheets(1).Range("A" & Sheets(1).Rows.Count).End(xlUp).Row
If Not Cells(i, 4).Value = "" Then
Next i
But this time, I went with the For Each, because I think it's a bit more readable.
Sub groupingEach()
Dim entry As Variant, prev As String, lRow As Long, lRow2 As Long
Dim inSht As Worksheet, outSht As Worksheet
Set inSht = Sheets(1)
Set outSht = Sheets(2)
lRow = inSht.Range("D" & inSht.Rows.Count).End(xlUp).Row 'last row
For Each entry In inSht.Range("D1:D" & lRow) 'loop 1st sheet
lRow2 = outSht.Range("D" & outSht.Rows.Count).End(xlUp).Row 'last row in output
If entry = prev And Not entry = "" Then
'-Group'
If InStr(outSht.Cells(lRow2, 3), entry.Offset(, 1)) = 0 Then 'does name exist?
outSht.Cells(lRow2, 3) = outSht.Cells(lRow2, 3) & vbNewLine & entry.Offset(, 1)
End If
outSht.Cells(lRow2, 5) = outSht.Cells(lRow2, 5) & vbNewLine & entry.Offset(, -2)
outSht.Cells(lRow2, 6) = outSht.Cells(lRow2, 6) + entry.Offset(, 2)
ElseIf Not entry = prev And Not entry = "" And Not entry = "Company" Then
'-New row
prev = entry 'Save company name for comparison
outSht.Cells(lRow2 + 1, 1) = entry.Offset(, -3)
outSht.Cells(lRow2 + 1, 2) = "Payable" 'Where to get this value?
outSht.Cells(lRow2 + 1, 3) = entry.Offset(, 1)
outSht.Cells(lRow2 + 1, 4) = entry
outSht.Cells(lRow2 + 1, 5) = entry.Offset(, -2)
outSht.Cells(lRow2 + 1, 6) = entry.Offset(, 2)
End If
Next entry
outSht.Cells(lRow2 + 3, 1).Value = "Grand Total:"
outSht.Cells(lRow2 + 3, 2).Formula = "=SUM(F:F)"
End Sub
From the examples, this should handle the document all the way from the Sample to the target. I wanted to loop the value copying, but the change in column order made it annoying.
Please help. I can not figure out how to get this to only search columns B and J exclusively. It is searching the range B:B through J:J. Everything else works fine.
Sub Find_Item(SNfound, SNRng, IDFound)
'The user is prompted to input either a serial number or unique ID number into a textbox on a userform.
'This is suppose to search only columns B (serial number) and J (ID number) in Table2 for the number the user entered
'Everything works except it is not limiting the search to only columns B and J. It is searching all columns from B through J.
Dim FindSNID As String
'note -- SNfound and IDFound are Dim As Boolean, SNRng is Dim As Range
Call ResetFilters 'this sub removes all filtering from the active sheet
FindSNID = SNID_textbox.Value
If Trim(FindSNID) <> "" Then
With Sheets("Inventory").Range("B:B", "J:J")
Set SNRng = .Find(What:=FindSNID, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not SNRng Is Nothing Then
SNRng.Activate
'If a match was found in column B (serial number) then display a MsgBox that the item was found and it's self location is xxxxxx from column W (offset 0,21)_
'and it's current status is either available or checked out (offset 0,23)
If SNRng.Column = 2 Then
MsgBox "A matching serial number was found in location " & SNRng.Offset(0, 21).Value & vbCrLf & _
"It's current status is " & SNRng.Offset(0, 23).Value
Areabox2.Value = SNRng.Offset(0, 28).Value
Sectionbox2.Value = SNRng.Offset(0, 29).Value
Shelfbox2.Value = SNRng.Offset(0, 30).Value
SNfound = True
IDFound = False
End If
'If a match is found in column J (ID Number)then the item's shelf location and status is displayed.
If SNRng.Column = 10 Then
MsgBox "A matching ID number was found in location " & SNRng.Offset(0, 13).Value & vbCrLf & _
"It's current status is " & SNRng.Offset(0, 15).Value
Areabox2.Value = SNRng.Offset(0, 28).Value
Sectionbox2.Value = SNRng.Offset(0, 29).Value
Shelfbox2.Value = SNRng.Offset(0, 30).Value
SNfound = False
IDFound = True
End If
End If
End With
End If
End Sub
Try creating the range by setting a range variable = Union(Range("B:B"), Range("J:J"))
I finally figured out how to get the Union method to work.
I changed this:
Set SNRng = .Find(What:=FindSNID, _
To this:
Set SNRng = Union(Range("B:B"), Range("J:J")).Find(What:=FindSNID, _
Now the search only searches columns B and J.
My issue is that I am trying to extract some information from a very large data sheet. The information that is being extracted is based on some search criteria that is entered on a form. The search form counts how many occurrences of this criteria exist, but then I need to extract the individual rows into a second sheet.
The bit I'm having difficulty with is understanding how to actually structure the extraction code. I'm in need of being pointed in the right direction. If the code can count how many occurrences there are, surely I can get the row numbers for those occurrences and extract the information, I'm just not getting anywhere trying to figure it out.
Here's my SEARCH code (this code works to get the number of occurrences based on the criteria asked)
Public Sub Run_Count_Click()
'// Set Ranges
Dim Cr_1, CR1_range, _
Cr_2, CR2_range, _
Cr_3, CR3_range, _
Cr_4, CR4_range, _
Cr_5, CR5_range _
As Range
'// Set Integers
Dim CR1, V1, CR1_Result, _
CR2, V2, CR2_Result, _
CR3, V3, CR3_Result, _
CR4, V4, CR4_Result, _
CR5, V5, CR5_Result, _
total_result, _
total_result2, _
total_result3, _
total_result4, _
total_result5 _
As Integer
'Set Strings
Dim V_1, V_2, V_3, V_4, V_5 As String
Dim ws As Worksheet
Set ws = Worksheets("database")
Sheets("Settings").Range("Start_Date").Value = Format(Me.R_Start.Value, "mm/dd/yyyy")
Sheets("Settings").Range("End_Date").Value = Format(Me.R_End.Value, "mm/dd/yyyy")
'Collect Start & End Dates
Dim dStartDate As Long
Dim dEndDate As Long
dStartDate = Sheets("Settings").Range("Start_Date").Value
dEndDate = Sheets("Settings").Range("End_Date").Value
ws.Activate
On Error GoTo error_Sdate:
Dim RowNum As Variant
RowNum = Application.WorksheetFunction.Match(dStartDate, Range("B1:B60000"), 0)
'MsgBox "Found " & Format(dStartDate, "dd/mm/yyyy") & " at row : " & RowNum
On Error GoTo error_Edate:
Dim RowNumEnd As Variant
RowNumEnd = Application.WorksheetFunction.Match(dEndDate, Range("B1:B60000"), 1)
' MsgBox "Found " & Format(dEndDate, "dd/mm/yyyy") & " at row : " & RowNumEnd
GoTo J1
error_Sdate:
Dim msg As String
msg = "You entered " & Format(dStartDate, "dd/mm/yyyy") & " as your Start Date, but no referrals were made on that date"
msg = msg & vbCrLf & "Please enter a different date in the Start Date box"
MsgBox msg, , "Start Date Not Found"
Err.Clear
Exit Sub
error_Edate:
msg = "You entered " & Format(dEndDate, "dd/mm/yyyy") & " as your End Date, but no referrals were made on that date"
msg = msg & vbCrLf & "Please enter a different date in the End Date box"
MsgBox msg, , "End Date Not Found"
Err.Clear
Exit Sub
J1:
'// Get Criteria From Form And Search Database Headers
Set Cr_1 = ws.Cells.Find(What:=Me.Count_Criteria_1.Value, After:=ws.Cells(1, 1), MatchCase:=False)
If Not Cr_1 Is Nothing Then
CR1 = Cr_1.Column '//Set CR1 as the Column in which the Criteria Header was found
Else
MsgBox "Criteria 1 Has Not Been Found In The Database. Report Has Failed To Generate"
Exit Sub
End If
'// Get Variable Value From Form And Set Shortcode
V_1 = Me.Criteria_1_Variable.Value
Set CR1_range = ws.Range(ws.Cells(RowNum, CR1), ws.Cells(RowNumEnd, CR1))
CR1_Result = Application.CountIf(CR1_range, V_1)
Me.Count_Result.visible = True
Me.Count_Result.Value = "Based On Your Search Criteria Of:" & vbNewLine & vbNewLine & _
"- " & Me.Count_Criteria_1.Value & ": " & Me.Criteria_1_Variable.Value & vbNewLine & vbNewLine & _
"The Results Are: " & CR1_Result & " entries found between the dates " & Format(dStartDate, "dd/mm/yyyy") & _
" and " & Format(dEndDate, "dd/mm/yyyy")
Exit Sub
Is there an easy way of doing this with a loop? I know loops are not the best way of handling things, but Im looking for anything that works and I can tweak to suit my needs.
Thanks if you can help in advance, it's a monster of a spreadsheet!
----------------------------
*Update With Accepted Answer:*
----------------------------
Public Sub Count_Extract_Click()
'Collect Information To Be Extracted
Set ws = Worksheets("database")
Set ps = Worksheets("Extracted Rows")
ps.Range("A3:AM60000").Clear
For i = RowNum To RowNumEnd
If ws.Cells(i, CR1).Value = V_1 Then
ws.Range("A" & i & ":AM" & i).Copy
ps.Activate
'find first empty row in database
emR = ps.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
ps.Range("A" & emR & ":AM" & emR).PasteSpecial
End If
Next i
End If
End Sub
You should be able to set a For loop to check each value in the range you've found and copy it to (another cell, an array, whatever you like.)
For i = rowNum To rowNumEnd
If Cells(i,CR1).Value = V_1 Then
MsgBox "Found match on row " & i
End If
Next i
I haven't tested this, but it should work. Let me know if you get any errors.
I can't really try this out, but maybe you can. Keep the line V_1 = Me.Criteria_1_Variable.Value but replace the next 2 by :
CR1_Result = 0 'Initiates counter at 0
Dim CR1_Lines(1000) As Long 'Declares an array of 1001 (indexes 0-1000) Longs (big integers)
For x = RowNum To RowNumEnd 'Loops through all the rows of CR1
If ws.Cells(x, CR1) = V_1 Then 'Match!
'Double array size if capacity is reached
If CR1_Result = UBound(CR1_Lines) Then
ReDim Presrve CR1_Lines(UBound(CR1_Lines) * 2)
End If
'Store that line number in the array
CR1_Lines(CR1_Result) = x
'Increment count of matches
CR1_Result = CR1_Result + 1
End If
Next x 'Next row!
You can then loop through that array with this code :
For i = 0 to UBound(CR1_Lines)
'Do something! (Why not just an annoying pop-up box with the content!)
MsgBox CR1_Lines(i)
Next i
EDIT : I just read that the spreadsheet is monstruous, and re-dimensioning every time a new match is found might be neat, but it's a hell of a performance drop. I made some changes directly in the above code to make it somewhat more effective.
EDIT #2 : I've simplified code so you don't have anything to do but a copy paste (please forgive me not assuming RowNum and RowNumEnd had valid data). It should work exactly as accepted answer, but was posted a bit before and actually shows how to extract the line number. I understand if all you needed is a pop-up box with the line number, and will be satisfied with the upvote already received.