Codeing help
Here's my code:
Private Sub cboOrgShp_Change()
Dim aRowcount As Integer
Dim expenditures As Range
Dim aOrgShp As String
aOrgShp = cboOrgShp.Value
Range("Expenditures").AutoFilter field:=2, Criteria1:=("aOrgShp")
With Range("expenditures")
If .EntireRow.Hidden = False Then
aRowcount = .Rows.Count
ActiveWorkbook.Names.Add Name:="OrgShp", _
RefersTo:="=" & .Parent.Name & "!" & .Resize(aRowcount).Address
txtSEQ.Value = aRowcount
End If
End With
End Sub
I can't seem to get it to work correctly. The range name ("Expenditures") is the range of all the rows with data in them. I need to filter the data range via a combobox named cboOrgShp. When the user selects the OrgShp I want the data filtered in the background. Then I want to count the (visible) rows (not including the headers) and assign the value to another Text Box labeled txtSeq, which will be entered onto the ActiveSheet. Finally, I need to unfilter the data back to original range. Basically, if the user filters by OrgShp, all the rows should be in sequential order with the number of the row in the far left column. When the ActiveSheet is unfiltered, the sequence numbers will invarialbly be out of order, which is fine.
Any help would be greatly appreciated.
The basic codeing for this will also be used (seperately and on a CommandButton) to sort the ActiveSheet by OrgShp and print the results.
|