In my code below, I'm trying to open up wb "Group1", find a perticular row in sheet "Kont", copy, and paste to sheet "Data1" in same wb.
I'm having problems with the find©-bit... Line "foundrow = ..." gives: Run-time error '91': Object variable or With block variable not set".
Anyone that can spot what's wrong - and how to fix it?
I'm having problems with the find©-bit... Line "foundrow = ..." gives: Run-time error '91': Object variable or With block variable not set".
Anyone that can spot what's wrong - and how to fix it?
Code:
Sub FindAndCopyPartOfRow() 'Open another wb, find sh and row and copy to another sh in same wb
Application.ScreenUpdating = False
Dim fPath As String
Dim wb_gr As Workbook
Dim sh_kont As Worksheet, sh_data As Worksheet
fPath = ThisWorkbook.Path
If Right(fPath, 1) = "\" Then
fPath = Left(fPath, Len(fPath) - 1)
End If
Set wb_gr = Workbooks.Open(ThisWorkbook.Path & "\group1.xlsm")
With wb_gr
Set sh_kont = .Worksheets("Kont")
Set sh_data = .Worksheets("Data1")
End With
[B]'These 4 lines work, but I don't want to use .activate and .select[/B]
'Windows("group1.xlsm").Activate
'Sheets("Kont").Select
'foundrow = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find("SUM alle kont", Cells(1, 1)).Row
'Range("G" & foundrow & ":EO" & foundrow).Copy
[B]'These 2 lines is what I've been trying to run[/B]
foundrow = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Find("SUM alle kont", Cells(1, 1)).Row
wb_gr.sh_kont.Range("G" & foundrow & ":EO" & foundrow).Copy
sh_data.Range("C" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
wb_gr.Save
wb_gr.Close False
End Sub