You aren't using Aaron's Function correctly
![]()
Find_Range("Yes", Range("W13:W100")).EntireRow.Select Selection.Copy Worksheets("Journal").Cells(Rows.Count, 1).End(xlUp)
You aren't using Aaron's Function correctly
![]()
Find_Range("Yes", Range("W13:W100")).EntireRow.Select Selection.Copy Worksheets("Journal").Cells(Rows.Count, 1).End(xlUp)
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
Your full code to use that Function would be
Note: rhe UDF (Function) is the work of Aaron Blood)![]()
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
Thanks for your reply RoyUK, i tried using that code last week after looking around on here but couldnt get it to work, i kept getting an error message
when i posted this thread i made some changes to the spreadsheet to make it easier to understand, but didnt make the changes to the code to reflect it
ive made the changes you suggested but im now getting a run time error 91
object variable or with block variable not set
it seems to have a problem with the line
Find_Range("Yes", Range("W13:W100")).EntireRow.Select
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
missed a line when i copied and pasted it!
now im getting a compile error, variable not defined for
firstAddress = c.Address
Aaron doesn't use Option Explicit, so you need to place
in the Function or remove Option Explicit.![]()
Dim FirstAddress as String
![]()
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
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?
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks