im having a bit of trouble moving from VB into VBA.
the xls file has 11 sheets
FrontPage, Sport1, Sport2,... Sport10
Sport1 to Sport10 contain 6 columns of Data with anything from 10 to 1000 rows
what i need to do is:-
call a subroutine from a button on "FrontPage".
an input box apears and the user enters a search criteria.
the search criteria is checked against all cells in column C.
if the criteria matches i need to copy the full row to a new sheet
now this is fine, if i just want to get rows from a single worksheet, but i need to search all 10 "Sport" worksheets
here is my bodged code for creating a search from 1 worksheet
ive experimented using
in an attempt to select across all 10 worksheets, but this doesnt seem to want to work.
any pointers how to neaten the code up, and obviously get it working, greatly appreciated
If somethings hard to do, its not worth doing - Homer Simpson
the xls file has 11 sheets
FrontPage, Sport1, Sport2,... Sport10
Sport1 to Sport10 contain 6 columns of Data with anything from 10 to 1000 rows
what i need to do is:-
call a subroutine from a button on "FrontPage".
an input box apears and the user enters a search criteria.
the search criteria is checked against all cells in column C.
if the criteria matches i need to copy the full row to a new sheet
now this is fine, if i just want to get rows from a single worksheet, but i need to search all 10 "Sport" worksheets
here is my bodged code for creating a search from 1 worksheet
Code:
Dim SelectString As String
SelectString = ""
'ask the user to select a part for example 2.1
SearchFor = InputBox("Enter a part", "", "0")
'if no part was entered or cancel was pressed, exit sub
If SearchFor = "" Or SearchFor = "0" Then
Exit Sub
End If
'lets look though all the cells in colum C for our part
For i = 2 To 32000
If Cells(i, 3) = CDbl(SearchFor) Then
'add the row to our selection string
SelectString = SelectString & "A" & i & ":" & "F" & i & ","
ElseIf IsEmpty(Cells(i, 3)) Then
'if the cell is empty assume were at the bottom
'of the list and exit loop
Exit For
End If
Next i
'remome trailing ","
SelectString = Mid(SelectString, 1, Len(SelectString) - 1)
'select our selection string
Range(SelectString).Select
'copy selection
Selection.Copy
'add a new worksheet
Worksheets.Add
'rename the sheet
ActiveSheet.Name = "SearchResults_" & SearchFor
'paste the info
ActiveSheet.Paste
ive experimented using
Code:
Selection.Clear
'loop through all worksheets
For Each Worksheet In Worksheets
SelectString = ""
If Not Worksheet.Name = "FrontPage" Then
For i = 2 To 32000
If Worksheet.Cells(i, 3) = dblSearchFor Then
SelectString = SelectString & "A" & i & ":" & "F" & i & ","
ElseIf IsEmpty(Worksheet.Cells(i, 3)) Then
SelectString = Mid(SelectString, 1, Len(SelectString) - 1)
Worksheet.Range(SelectString).Select
Exit For
End If
Next i
End If
Next Worksheet
in an attempt to select across all 10 worksheets, but this doesnt seem to want to work.
any pointers how to neaten the code up, and obviously get it working, greatly appreciated
If somethings hard to do, its not worth doing - Homer Simpson