Indsæt kopiret område i første ledige række

Eskild

New Member
Joined
May 6, 2019
Messages
5
Hej.
Jeg har et problem, og jeg kan ikke lure, hvorfor den melder fejl.
Jeg er ved at lave en VBA-kode, som kan åbne en excel fil, kopiere et bestemt område, og derefter lukke igen.. Denne del virker vidst optimalt?
Det næste er, at jeg skal kopiere et område i et ark og sætte det over, hvor den første ledige celle/række er i kolonne B. - Denne del er problemet.
Endvidere skal jeg have den til at kopiere det, sådan at der kun indsættes værdien (altså ikke formlen)

Jeg har indtilvidere denne stykke kode:
Jeg beklager at den er så rodet, men jeg har bøvlet med det et stykke tid.


Sub Get_Data_From_File()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False

FileToOpen = Application.GetOpenFilename(Title:="Find den journal du ønsker at importere", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:L40").Copy
ThisWorkbook.Worksheets("Ark3").Range("A1:L40").PasteSpecial xlPasteValues
OpenBook.Close False

End If
Application.ScreenUpdating = True

Sub FindTomogindsætdata()

Sheets("Ark3").Activate
Range("O13:AB25").Copy

Sheets("Ark2").Activate
Range("B15:B1000").Find(Empty, LookIn:=xlValues).Select
Selection.PasteSpecial xlPasteValues
End Sub

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:

VBA Code:
Sub Get_Data_From_File()
  Dim FileToOpen As Variant
  Dim OpenBook As Workbook
  Application.ScreenUpdating = False
  
  FileToOpen = Application.GetOpenFilename(Title:="Find den journal du ønsker at importere", FileFilter:="Excel Files (*.xls*),*xls*")
  If FileToOpen <> False Then
  Set OpenBook = Application.Workbooks.Open(FileToOpen)
  OpenBook.Sheets(1).Range("A1:L40").Copy
  ThisWorkbook.Worksheets("Ark3").Range("A1:L40").PasteSpecial xlPasteValues
  OpenBook.Close False
  
  End If
  Application.ScreenUpdating = True
End Sub

VBA Code:
Sub FindTomogindsætdata()
  Sheets("Ark3").Activate
  Range("O13:AB25").Copy
  
  Sheets("Ark2").Activate
  Range("B" & Rows.Count).End(3)(2).PasteSpecial xlPasteValues
End Sub
 
Upvote 0
Hej Dante.
Thanks for reply!
My subscript says out of range...
Is it possible to get it to open, and copy the cells, then close it again, and paste it in the already open sheet?
 
Upvote 0
in which of the 2 macros?
or is it a single macro?
 
Upvote 0
If it could be one macro, it could be nice, but i cant figure out how to do it all in one macro... But 1 macro is the dream.

It schoul open an excel file, copy a range in the opend.
Then insert it in a sheet called "rammeliste" in my opened woorksheet.
Then it need to copy another range, and insert it in a sheet called "Ark 2", in the first empty row in column b.

Everytime i do it, it inserts it in the bottum of my sheet.
 
Upvote 0
Then insert it in a sheet called "rammeliste" in my opened woorksheet.
Then it need to copy another range, and insert it in a sheet called "Ark 2", in the first empty row in column b.
Your 2 macros don't do that.
Better explain step by step what you need
(book-sheet-range) .copy
(book-sheet-range) .paste
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,033
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top