copy many files into one

  • Thread starter Thread starter Gabriel
  • Start date Start date
G

Gabriel

Hi,

I want to copy the usedranges from many files into one excel file. I
want those usedranges to be appended to the last column and not to the
last row. I thought that this part would do it, but it doesn't

Destination:=TargetSht.Cells(1, Columns.Count).End(xlLeft).Offset(0,
1)

Can anyone help please ?
Thank you
Gabriel
 
You can also use a function to find the last column with data
Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End FunctionSub test()
MsgBox Lastcol(ActiveSheet)
End Sub
 
This is a mess<g>

Try this

You can also use a function to find the last column with data

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function

Sub test()
MsgBox Lastcol(ActiveSheet)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top