Option Explicit
' Copies sheets ranges (values and formats) from a closed workbook into
' a sheet on the opened workbook.
Private Sub copySheets(fileName As String, sheetName As String, dstSheetName As String, rng As String)
Sheets(dstSheetName).Cells.Clear
Dim srcWB As Workbook
' Open the source workbook and copy the values
Set srcWB = Workbooks.Open(fileName)
srcWB.Sheets(sheetName).Range(rng).Copy
ThisWorkbook.Activate
' Paste values and formats
With Sheets(dstSheetName)
.Range(rng).PasteSpecial Paste:=xlPasteFormats
.Range(rng).PasteSpecial Paste:=xlPasteColumnWidths
.Range(rng).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End With
' Get out of the copy mode
Application.CutCopyMode = False
' Close the source workbook without saving
srcWB.Close savechanges:=False
End Sub
' An example of use
Public Sub diff()
Dim fileName As String
' Copy 2 sheets from 2 different files
' The first file
' Get the file names from a cell
fileName = Sheets("Main").Range("B1").Value
copySheets fileName, "Summary", "Summary", "A1:M26"
copySheets fileName, "Day Positions", "DayPositions", "A1:N32"
' The second file
fileName = Sheets("Main").Range("B2").Value
copySheets fileName, "Summary", "SummaryNew", "A1:M26"
copySheets fileName, "Day Positions", "DayPositionsNew", "A1:N32"
ThisWorkbook.Sheets("Diff").Activate
ThisWorkbook.Save
End Sub
Thursday, June 11, 2020
Saturday, April 4, 2020
Project Valhalla
The OpenJDK page:
http://openjdk.java.net/projects/valhalla/
State of Valhalla (Brian Goetz):
Basically going from:

To:
Monday, January 13, 2020
2020 Holiday Schedule
Date | Holiday |
---|---|
Wednesday, January 1 | New Year’s Day |
Monday, January 20 | Birthday of Martin Luther King, Jr. |
Monday, February 17* | Washington’s Birthday |
Monday, May 25 | Memorial Day |
Friday, July 3** | Independence Day |
Monday, September 7 | Labor Day |
Monday, October 12 | Columbus Day |
Wednesday, November 11 | Veterans Day |
Thursday, November 26 | Thanksgiving Day |
Friday, December 25 | Christmas Day |
*This holiday is designated as
"Washington’s Birthday" in section 6103(a) of title 5 of the United
States Code, which is the law that specifies holidays for Federal
employees. Though other institutions such as state and local governments
and private businesses may use other names, it is our policy to always
refer to holidays by the names designated in the law.
**July 4, 2020 (the legal public holiday for Independence Day), falls on a Saturday. For most Federal employees, Friday, July 3, will be treated as a holiday for pay and leave purposes. (See 5 U.S.C. 6103(b).)
Friday, May 31, 2019
GNU date and relatives dates
I was writing a simple script to delete some log files, all the log filenames contain the date of creation in the form YYYYMMDD and I needed to delete the files from previous month keeping the current month. The script will run on the last day of every month.
I thought the task will be very easy as I could use the GNU date command to build the date string, something like:
# The year
date +%Y
Use the date relative option for getting the previous month, something like:
date --date="-1 month" +%m
Then concatenate both strings and build a file pattern using wildcards like ? and *.
The system date was 2019-05-31 ahd I was expecting the 04 string as the output, instead 05 was printed.
I tried several variants and all printed the same, 05:
$ date --date="-1 month" +%m
05
$ date --date="last month" +%m
05
I DuckDuckGoed the Internet and found this answer:
https://stackoverflow.com/questions/13168463/using-date-command-to-get-previous-current-and-next-month
This is from the coreutils manual online:
https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings
$ date --date="$(date +%Y%m15) -1 month" +%m
04
I thought the task will be very easy as I could use the GNU date command to build the date string, something like:
# The year
date +%Y
Use the date relative option for getting the previous month, something like:
date --date="-1 month" +%m
Then concatenate both strings and build a file pattern using wildcards like ? and *.
The system date was 2019-05-31 ahd I was expecting the 04 string as the output, instead 05 was printed.
I tried several variants and all printed the same, 05:
$ date --date="-1 month" +%m
05
$ date --date="last month" +%m
05
I DuckDuckGoed the Internet and found this answer:
https://stackoverflow.com/questions/13168463/using-date-command-to-get-previous-current-and-next-month
This is from the coreutils manual online:
https://www.gnu.org/software/coreutils/manual/html_node/Relative-items-in-date-strings.html#Relative-items-in-date-strings
$ date --date="$(date +%Y%m15) -1 month" +%m
04
Wednesday, May 8, 2019
PDFs don't open automatically in Chrome
You can normally open PDFs automatically in Chrome by clicking on the file you want to see. If your PDFs are downloading instead of opening automatically in Chrome, Chrome PDF viewer could be turned off.
Open PDFs in Chrome
- On your computer, open Chrome.
- At the top right, click More
Settings.
- At the bottom, click Advanced.
- Under "Privacy and security," click Site settings.
- Near the bottom, click PDF documents.
- Turn off Download PDF files instead of automatically opening them in Chrome.
Chrome will now open PDFs automatically when you click them.
Monday, March 4, 2019
2019 Holiday Schedule
Date | Holiday |
---|---|
Tuesday, January 1 | New Year’s Day |
Monday, January 21 | Birthday of Martin Luther King, Jr. |
Monday, February 18* | Washington’s Birthday |
Monday, May 27 | Memorial Day |
Thursday, July 4 | Independence Day |
Monday, September 2 | Labor Day |
Monday, October 14 | Columbus Day |
Monday, November 11 | Veterans Day |
Thursday, November 28 | Thanksgiving Day |
Wednesday, December 25 | Christmas Day |
*This holiday is designated as "Washington’s Birthday" in section 6103(a) of title 5 of the United States Code, which is the law that specifies holidays for Federal employees. Though other institutions such as state and local governments and private businesses may use other names, it is our policy to always refer to holidays by the names designated in the law.
Taken from: https://www.opm.gov/policy-data-oversight/snow-dismissal-procedures/federal-holidays/#url=2019
Monday, October 1, 2018
How to Find Multiple Missing Integers in Given Array With Duplicates in Java?
I found this interesting problem here:
https://javarevisited.blogspot.com/2014/11/how-to-find-missing-number-on-integer-array-java.html
but I think the solution is too long, see mine below:
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class MissingIntegers {
public static void main(String[] args) {
Set<Integer> s1 = new HashSet<>(Arrays.asList(new Integer[]{1, 2, 3, 4, 9, 8}));
Set<Integer> s2 = new HashSet<>(IntStream.rangeClosed(1, 10).boxed().collect(Collectors.toList()));
s2.removeAll(s1);
System.out.println(s2);
}
}
In fact we don't need the intermediate List in the case of Set 2, we can use the toCollection method of Collectors:
Set<Integer> s2 = IntStream.rangeClosed(1, 10).boxed().collect(Collectors.toCollection(HashSet::new));
Next day I came up with another solution:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class MissingIntegers {
public static void main(String[] args) {
List<Integer> L1 = Arrays.asList(new Integer[]{1, 2, 3, 4, 9, 2, 8});
List<Integer> L2 = IntStream.rangeClosed(1, 10).boxed().collect(Collectors.toCollection(ArrayList::new));
L2.removeAll(L1);
System.out.println(L2);
}
}
Subscribe to:
Posts (Atom)