jvantassel1
asked on
fisrst visible row with autofilter
need to determine the first and last visible cell to set limits for a loop.
the code below doesn't quite work. I viewed the other solutions, but didn't get them to work.
code
Sub test()
Dim k As Integer
Dim strSearch As Variant
Dim searchedRow As Variant
Dim dateAddress As Variant
Dim cntMDEP As Variant
Dim offset1, offset2, offset3 As Integer
Dim date1 As Variant
Dim CalcMode As Variant
Dim ViewMode As Variant
Dim dateFound As String
Dim myRange, RangeClear, rngLoop As Range
Dim nFld1, nCrit1 As Variant
Dim varPEG As Variant
Dim startLoop, endLoop As Double
Dim varTest As Variant
Set rngLoop = Range("A15", Cells(ActiveSheet.UsedRang e.Rows.Cou nt, _
Range("A15").Column)).Spec ialCells(x lCellTypeV isible)
Dim v As Range
Set v = Range("A15:A" & Cells(Rows.Count, "A").End(xlUp).Row).Specia lCells(xlC ellTypeVis ible)
MsgBox "the cell address is: " & v.Address
'15 is number of rows we start from
endLoop = 15 + rngLoop.Count
startLoop = "" ' get row number so know where to start
'do stuff here
For k = startLoop To endLoop
Next k
End Sub
Get-first-and-last-cell-from-aut.xlsm
the code below doesn't quite work. I viewed the other solutions, but didn't get them to work.
code
Sub test()
Dim k As Integer
Dim strSearch As Variant
Dim searchedRow As Variant
Dim dateAddress As Variant
Dim cntMDEP As Variant
Dim offset1, offset2, offset3 As Integer
Dim date1 As Variant
Dim CalcMode As Variant
Dim ViewMode As Variant
Dim dateFound As String
Dim myRange, RangeClear, rngLoop As Range
Dim nFld1, nCrit1 As Variant
Dim varPEG As Variant
Dim startLoop, endLoop As Double
Dim varTest As Variant
Set rngLoop = Range("A15", Cells(ActiveSheet.UsedRang
Range("A15").Column)).Spec
Dim v As Range
Set v = Range("A15:A" & Cells(Rows.Count, "A").End(xlUp).Row).Specia
MsgBox "the cell address is: " & v.Address
'15 is number of rows we start from
endLoop = 15 + rngLoop.Count
startLoop = "" ' get row number so know where to start
'do stuff here
For k = startLoop To endLoop
Next k
End Sub
Get-first-and-last-cell-from-aut.xlsm
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help. I didn't work this weekend, so couldn't test until today.
this works to walk through the rows. but I tried to replace k, which was an integer with rw within the following code, but it's not working. When the user clicks the link "... update dates..." the code searches each MDEP for the given row, then looks up the date from the "Schedule Room" tab and writes the date in either MB1, MB2 or PB if there is one. Download the attached workbook to see all the code. It was working well before I realized I need to do this by PEG.
With Worksheets("MB Status Tracker").Range("B15")
For offset1 = 3 To 5 ' DKB Added to go through the MB2 & PB
'For k = 1 To 159
For Each rw In rngLoop.SpecialCells(xlCel lTypeVisib le).Rows
Worksheets("MB Status Tracker").Activate
'.Offset(rw, 0).Activate 'replaced k with rw
searchedRow = ActiveCell.Row
.Offset(rw, 10).Value = ActiveCell.Row 'replaced k with rw
strSearch = .Offset(rw, 0).Value 'replaced k with rw
'go find the record
'the second parameter passed to findMDEP is the number you are searching for (1,2, or 3)
dateFound = findMDEP(strSearch, offset1 - 2)
If (dateFound <> "") Then
Worksheets("MB Status Tracker").Cells(searchedRo w, offset1) = dateFound
'MsgBox findMDEP(strSearch)
'cntMDEP = cntMDEP + findMDEP(strSearch)
End If
Next rw 'k
Next offset1
End With
Worksheets("MB Status Tracker").Activate
POM-1620-Murder-Board-Dates-and-.xlsm
this works to walk through the rows. but I tried to replace k, which was an integer with rw within the following code, but it's not working. When the user clicks the link "... update dates..." the code searches each MDEP for the given row, then looks up the date from the "Schedule Room" tab and writes the date in either MB1, MB2 or PB if there is one. Download the attached workbook to see all the code. It was working well before I realized I need to do this by PEG.
With Worksheets("MB Status Tracker").Range("B15")
For offset1 = 3 To 5 ' DKB Added to go through the MB2 & PB
'For k = 1 To 159
For Each rw In rngLoop.SpecialCells(xlCel
Worksheets("MB Status Tracker").Activate
'.Offset(rw, 0).Activate 'replaced k with rw
searchedRow = ActiveCell.Row
.Offset(rw, 10).Value = ActiveCell.Row 'replaced k with rw
strSearch = .Offset(rw, 0).Value 'replaced k with rw
'go find the record
'the second parameter passed to findMDEP is the number you are searching for (1,2, or 3)
dateFound = findMDEP(strSearch, offset1 - 2)
If (dateFound <> "") Then
Worksheets("MB Status Tracker").Cells(searchedRo
'MsgBox findMDEP(strSearch)
'cntMDEP = cntMDEP + findMDEP(strSearch)
End If
Next rw 'k
Next offset1
End With
Worksheets("MB Status Tracker").Activate
POM-1620-Murder-Board-Dates-and-.xlsm
k referred to a row number.
Now, rw is a range object. So, if you change rw to rw.row it should work.
Joop
Now, rw is a range object. So, if you change rw to rw.row it should work.
Joop
ASKER
Thanks, once I realized I could use rw.row it all came together.
ASKER
Joop's solution worked best for me. I appreciate the help.
Set rngLoop = Range("A15", Cells(ActiveSheet.UsedRang
Range("A15").Column)).Spec