+ Reply to Thread
Results 1 to 11 of 11

Macro

Hybrid View

  1. #1
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Have you still got the Function in there?

    Option explicit
    Sub PrepareUpload()
        Dim ws     As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            Select Case ws.Name
                Case "Journal"    'do nothing
                Case Else
                    Find_Range("Yes", Range("W13:W100")).EntireRow.Select
                    Selection.Copy Worksheets("Journal").Cells(Rows.Count, 1).End(xlUp)
            End Select
        Next ws
    End Sub
    Function Find_Range(Find_Item As Variant, _
                        Search_Range As Range, _
                        Optional LookIn As Variant, _
                        Optional LookAt As Variant, _
                        Optional MatchCase As Boolean) As Range
    
        Dim c      As Range
        If IsMissing(LookIn) Then LookIn = xlValues    'xlFormulas
        If IsMissing(LookAt) Then LookAt = xlPart    'xlWhole
        If IsMissing(MatchCase) Then MatchCase = False
    
        With Search_Range
            Set c = .Find( _
                    What:=Find_Item, _
                    LookIn:=LookIn, _
                    LookAt:=LookAt, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, _
                    MatchCase:=MatchCase, _
                    SearchFormat:=False)
            If Not c Is Nothing Then
                Set Find_Range = c
                firstAddress = c.Address
                Do
                    Set Find_Range = Union(Find_Range, c)
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
    
    End Function
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  2. #2
    Registered User
    Join Date
    09-20-2005
    Posts
    14
    missed a line when i copied and pasted it!

    now im getting a compile error, variable not defined for

    firstAddress = c.Address

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Aaron doesn't use Option Explicit, so you need to place

    Dim FirstAddress as String
    in the Function or remove Option Explicit.

    Function Find_Range(Find_Item As Variant, _
                        Search_Range As Range, _
                        Optional LookIn As Variant, _
                        Optional LookAt As Variant, _
                        Optional MatchCase As Boolean) As Range
    
        Dim c      As Range
        Dim firstAddress As String
     'etc

  4. #4
    Registered User
    Join Date
    09-20-2005
    Posts
    14
    thanks for your help RoyUK

    im still getting the runtime 91 error though, before i input the Dim firstAddress As String line i was getting the error in my previous post, but since ive inserted this line im getting the 91 error again

    my code at the moment is:

    Option Explicit
    Sub PrepareUpload()
        Dim ws     As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            Select Case ws.Name
                Case "Journal"    'do nothing
                Case Else
                    Find_Range("Yes", Range("W13:W100")).EntireRow.Select
                    Selection.Copy Worksheets("Journal").Cells(Rows.Count, 1).End(xlUp)
            End Select
        Next ws
    End Sub
    Function Find_Range(Find_Item As Variant, _
                        Search_Range As Range, _
                        Optional LookIn As Variant, _
                        Optional LookAt As Variant, _
                        Optional MatchCase As Boolean) As Range
    
        Dim c      As Range
        Dim firstAddress As String
        If IsMissing(LookIn) Then LookIn = xlValues    'xlFormulas
        If IsMissing(LookAt) Then LookAt = xlPart    'xlWhole
        If IsMissing(MatchCase) Then MatchCase = False
    
        With Search_Range
            Set c = .Find( _
                    What:=Find_Item, _
                    LookIn:=LookIn, _
                    LookAt:=LookAt, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, _
                    MatchCase:=MatchCase, _
                    SearchFormat:=False)
            If Not c Is Nothing Then
                Set Find_Range = c
                firstAddress = c.Address
                Do
                    Set Find_Range = Union(Find_Range, c)
                    Set c = .FindNext(c)
                Loop While Not c Is Nothing And c.Address <> firstAddress
            End If
        End With
    
    End Function

    any ideas?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    If it isn't finding any Rows it errors. This seems to work

    Sub PrepareUpload()
        Dim ws     As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            Application.ScreenUpdating = False
            On Error Resume Next
            Select Case ws.Name
                Case "Journal"    'do nothing
                Case Else
                    ws.Select
                    Find_Range("Yes", ws.Range("W13:W100")).EntireRow.Select
                    Selection.Copy Worksheets("Journal").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            End Select
        Next ws
        Application.ScreenUpdating = True
        On Error GoTo 0
    End Sub

  6. #6
    Registered User
    Join Date
    09-20-2005
    Posts
    14
    RoyUK That works a treat! - thankyou for all your help, its much appreciated!

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    That's relief(LOL). Glad we worked it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1