Loop through filtered values in excel - vbscript

I am trying to automatically apply filter on a column in the excel sheet and I have to loop through the filtered values available on different column.I am not getting how to loop through the filtered values?
Applying filter on 19th column.Have to loop through the values available on 12th column.
strPath="C:\Users\PSi\Desktop\CodeIn.xlsx"
Dim ProcessName
ProcessName=Trim(InputBox("Process Name:"))
Set objExcel= CreateObject("Excel.Application")
objExcel.Visible= True
objExcel.Workbooks.Open(strPath)
With objExcel.Activeworkbook.Sheets("All")
.Range("A1").AutoFilter 19,"="&ProcessName
End With
'How to loop through the filtered values ??
'Need to loop through only on the above filtered values..
for i=2 to (How to get end of filtered used rows)
if Mid(objExcel.Activeworkbook.Sheets("All").Cells(i,12).Value,1,3)="Seq"
Then msgbox objExcel.Activeworkbook.Sheets("All").Cells(i,12).Value
End if
Next

Related

Repeating Cell Fill In Randomly Selected Rows

I want to auto-fill the text "SOLD" to column K in each row from a pre-chosen set of rows not necessarily in sequential order. For ex: I may select rows 1-3 & maybe rows 8 & 10. Upon selecting said rows, I want to run my macro to enter the text "SOLD" in each of them.
Here is my current macro, which works only on one row at a time:
Sub ItemSold()
Range("K" & ActiveCell.Row).Select
ActiveCell.FormulaR1C1 = "SOLD"
Rows(ActiveCell.Row).Select
End Sub
I assume there's a way to cycle through all of the selected rows with FOR EACH or maybe a REPEAT function/?

Excel for Mac VBA - Go to specific row of table and work up the rows to first row

I´d like to find a specific row of a table in Excel for Mac 2011. From this row, I want to work up the table to the 1st row. I´m sure there is a simple way of doing it.
Also, what is the tweak, to work down to the end of the table from a specified row?
Thanks in Advance!!
You might want to provide an idea of what you have tried...as well as how you want to find the starting row. Regardless, here I have finding the end row of your data (based on column A, change as needed). This goes to the bottom of the sheet, then essentially does Ctrl + up arrow to get the last row that has something in it. Then starts from there and steps backwards through the rows until row 1. Nb you don't have to set i to endRow, I just did in case you wanted to use endRow for something else.
Public Sub testing()
Dim ws As Worksheet
Dim endRow As Integer
Dim i As Integer
Set ws = ThisWorkbook.Worksheets("Sheet1")
endRow = ws.Range("A" & Rows.Count).End(xlUp).row
i = endRow
While i >= 1
'Working up the sheet doing whatever
i = i - 1
Wend
End Sub

Access word documents header containing a table with vbscript

I need to read the pure text values from cells of a table located in the page header of a word document using vbscript.
All i could achieve until now is to read some kind of text from the header by this:
wscript.echo WordApp.ActiveDocument.Sections(1).Headers(1).Range.FormattedText.Text
But how can i gain access to the table object and read each cell value?
Tables in Word documents can be enumerated via the Tables collection.
For Each tbl In WordApp.ActiveDocument.Sections(1).Headers(1).Range.Tables
For i = 1 To tbl.Rows.Count
For j = 1 To tbl.Columns.Count
WScript.Echo tbl.Cell(i, j).Value
Next
Next
Next

Does ADO Recordset need to be closed?

I have an ADO recordset (not ADO.NET) that I populate in every iteration of a loop.
My question is: Do I need to close the recordset at end of every iteration so it gets populated with fresh data in next iteration OR I could just use the unclosed recordset to populate with new data in next iteration. Please look at code sample below.
set rs=Server.CreateObject("ADODB.recordset")
for count = 0 to 3
rs.Open "Select * from Customers where CustomerId = " & count, conn
'do some processing of data in recordset
'rs.Close 'NOT VERY SURE IF I NEED TO DO THIS
next
You cannot open a recordset again :
Error 3705 : Operation is not allowed when the object is open
So given the sample above which requires a different selection of data, you must close the recordset.

Filtering a validation list based on columns within a named range

I am looking for a way to filter a list validation in Excel based on a multi-column named range.
I have a list of product releases on one sheet, contained in a named range that has the columns: Name, Type, Status. On another sheet, I want the user to be able to select from a validation list containing 'Name' only.
Question 3741060 here covers how to make the validation list only contain the 'Name' column. However I also need to filter so that the user cannot select a release with the status 'Completed'. [The status column only allows 'Planned', 'Allocated' or 'Completed'.]
Ideally I would also like to dynamically show only 'Planned' OR 'Allocated' releases based on yet another validation - but I think if I can get the list filtered at all I should be able to do the rest.
BTW - I am forced to use Excel 2003 for this, although I don't believe would be a major factor.
I use
an extra range LOV (for List of Values) in a hidden sheet that I fill with the current criteria the user can choose from (in my case this varies from line to line as he/she fills the sheet)
all cells in the main sheet are validated against this range LOV
a Selection_Change() trigger loads the LOV after each cursor move from the original range of possible choices
This is how I re-generate my LOV (in essence the user has already selected a country code in another cell passed here in string CtyCd, and the sheet now is prepered to offer a selection of possible choices of something called GINI for only this country ... so maybe similar to your demand)
Sub LoadL2LOV(CtyCd As String, LOVL2 As Range)
'
' CtyCd is a selection criterium for the original list in range GINI
' LOVL2 is the target range containing the current list of values
' all cells in sheet have a validation against range LOV defined
'
Dim GINI As Range, Idx As Long, Jdx As Long, LName As Name, Adr As String
' clear current PoP_L2
Set LName = ActiveWorkbook.Names(LOVL2.Name.Name)
Set GINI = Worksheets("GINI Availability").Range("GINI")
LOVL2.ClearContents
' set new LOV for PoP_L2
If CtyCd <> "" Then
Idx = 2
Jdx = 1
' find 1st occurence of CtyCd in GINI
Do While GINI(Idx, 4) <> CtyCd And GINI(Idx, 4) <> ""
Idx = Idx + 1
Loop
' GINI is sorted, just read until the end of selected CtyCd
Do While GINI(Idx, 4) = CtyCd
LOVL2(Jdx, 1) = GINI(Idx, 1) & "-" & GINI(Idx, 2) & "-" & GINI(Idx, 3)
Idx = Idx + 1
Jdx = Jdx + 1
Loop
End If
' redefine LOV name to contain all current valid choices
LOVL2.CurrentRegion.Name = LOVL2.Name.Name
End Sub
In your case, as the data seems to be more or less static, you can copy all valid selections from [Prod_Release] to LOV at Sheet_Activate or any appropriate activation trigger.
Hope this helps .... good luck MikeD

Resources