VBA Magician required

mikemcbain

Board Regular
Joined
Nov 14, 2005
Messages
97
Office Version
  1. 365
Platform
  1. Windows
I use Excel for Office 365 in Windows 10.

I have a spreadsheet called C:/Desktop/tkxl_f.xlsm which can have from two to twenty five sheets each with different and variable names and always located between a sheet called Blank and a sheet called Cover.

I wish to copy and paste the range A1:K133 from each of these sheets onto a worksheet called Today in another spreadsheet called C:/Desktop/20190101_2019.xlsm one below the other.

Is it possible or am I asking too much? My macro skills are limited to recording simple stuff.

In anticipation

Mike
Tasmania.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
1,630
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
This assumes that both workbooks are closed and the code is in a third workbook that is open. (or in your personal.xlsb)
I don't think that your path to the desktop is right, if that is where the workbooks are saved and not in a Folder named "Desktop" on the C Drive.
To get your path to the desktop, you can use this.
Code:
Sub ABCDE()
MsgBox Environ("USERPROFILE") & "\Desktop"
End Sub
or you can change the two lines in question to
Set wbFrom = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\tkxl_f.xlsm")
Set wbTo = Workbooks.Open(CreateObject("WScript.Shell").specialfolders("Desktop") & "\20190101_2019.xlsm")


Code:
Sub Maybe()
Dim wbFrom As Workbook, wbTo As Workbook, sh1 As Worksheet, i As Long
Set wbFrom = Workbooks.Open("C:/Desktop/tkxl_f.xlsm")
Set wbTo = Workbooks.Open("C:/Desktop/20190101_2019.xlsm")
Set sh1 = wbTo.Sheets("Today")
    For i = wbFrom.Sheets("Blank").Index + 1 To wbFrom.Sheets("Cover").Index - 1
        With sh1
            .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(133, 11).Value = wbFrom.Sheets(i).Range("A1:K133").Value
        End With
    Next i
wbFrom.Close False
wbTo.Close True
End Sub
 

mikemcbain

Board Regular
Joined
Nov 14, 2005
Messages
97
Office Version
  1. 365
Platform
  1. Windows
jolivanes

You are a true magician!
Once I corrected my Desktop location your simple VBA worked an absolute treat.
I am so grateful and can't wait to exploit your work which will save me much time and angst.

Mike.
 

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
1,630
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
Mike
Thanks for letting us know and good luck
 

Watch MrExcel Video

Forum statistics

Threads
1,109,359
Messages
5,528,226
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top