Friday, January 18, 2019

Useful Excel Macro

Save worksheets as text files

Sub SaveSheetsAsTextFiles()
  Dim originalFileName As String
  Dim originalSheetName As String
  Dim anyWS As Worksheet
  Dim rootPath As String
  Dim newName As String
  Dim theYear As String
  Dim theMonth As String
  Dim theDay As String
  Dim whereAmI As String

  'you can assign a path to this like
  ' rootPath = "C:\folder1\folder2\folder3\"
  'but this uses path to folder where the
  'Excel file is stored
  rootPath = ActiveWorkbook.path
  If Right(rootPath, 1) <> Application.PathSeparator Then
    rootPath = rootPath & Application.PathSeparator
  End If
  originalFileName = ActiveWorkbook.FullName ' path and name!
  theYear = CStr(Format(Year(Now()), "0000")) ' 4 digit year
  theMonth = CStr(Format(Month(Now()), "00")) ' 2 digit month
  theDay = CStr(Format(Day(Now()), "00")) ' 2 digit day
  'remember where we are in the workbook
  whereAmI = ActiveSheet.Name
  'turn off alerts to the user
  Application.DisplayAlerts = False
  'prevent screen flickering and improve speed
  Application.ScreenUpdating = False
  For Each anyWS In ActiveWorkbook.Worksheets
    'must actually activate the sheet
    anyWS.Activate
    originalSheetName = ActiveSheet.Name
    'set up new name for the text file
    'you can easily change the sequence for the date portion
    'as set up all sheet names will be grouped together and
    'in date order from newest to oldest when viewed in file browser
    newName = rootPath & ActiveSheet.Name _
     & ".txt"
    'save the sheet as a TAB DELIMITED text file
    ActiveWorkbook.SaveAs _
     Filename:=newName, FileFormat:=xlText
    'change the sheet name back to its original name
    anyWS.Name = originalSheetName
  Next
  'and get the workbook back to its original name
  ActiveWorkbook.SaveAs _
   Filename:=originalFileName, FileFormat:=xlNormal
  'restore normal user alerting feature
  Application.DisplayAlerts = True
  'and return to the sheet you started on
  Worksheets(whereAmI).Activate
End Sub

Save worksheets as csv files

Sub ExportSheetsToCSV()
  Dim originalFileName As String
  Dim originalSheetName As String
  Dim anyWS As Worksheet
  Dim rootPath As String
  Dim newName As String
  Dim theYear As String
  Dim theMonth As String
  Dim theDay As String
  Dim whereAmI As String

  'you can assign a path to this like
  ' rootPath = "C:\folder1\folder2\folder3\"
  'but this uses path to folder where the
  'Excel file is stored
  rootPath = ActiveWorkbook.Path
  If Right(rootPath, 1) <> Application.PathSeparator Then
    rootPath = rootPath & Application.PathSeparator
  End If
  originalFileName = ActiveWorkbook.FullName ' path and name!
  theYear = CStr(Format(Year(Now()), "0000")) ' 4 digit year
  theMonth = CStr(Format(Month(Now()), "00")) ' 2 digit month
  theDay = CStr(Format(Day(Now()), "00")) ' 2 digit day
  'remember where we are in the workbook
  whereAmI = ActiveSheet.Name
  'turn off alerts to the user
  Application.DisplayAlerts = False
  'prevent screen flickering and improve speed
  Application.ScreenUpdating = False
  For Each anyWS In ActiveWorkbook.Worksheets
    'must actually activate the sheet
    anyWS.Activate
    originalSheetName = ActiveSheet.Name
    'set up new name for the text file
    'you can easily change the sequence for the date portion
    'as set up all sheet names will be grouped together and
    'in date order from newest to oldest when viewed in file browser
    newName = rootPath & "VO_CSVs_Ankur\" & ActiveSheet.Name _
     & ".csv"
    'save the sheet as a TAB DELIMITED text file
    ActiveWorkbook.SaveAs _
     Filename:=newName, FileFormat:=xlCSV
    'change the sheet name back to its original name
    anyWS.Name = originalSheetName
  Next
  'and get the workbook back to its original name
  ActiveWorkbook.SaveAs _
   Filename:=originalFileName, FileFormat:=xlNormal
  'restore normal user alerting feature
  Application.DisplayAlerts = True
  'and return to the sheet you started on
  Worksheets(whereAmI).Activate
End Sub


Replace all endline characters

Sub RemoveCarriageReturns()
    Dim MyRange As Range
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    For Each MyRange In ActiveSheet.UsedRange
        If 0 < InStr(MyRange, Chr(13)) Then
            MyRange = Replace(MyRange, Chr(13), "")
        End If
    Next

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub

Tuesday, December 4, 2018

Finding Columns will null or empty values in Oracle Database Tables

Gather Statistics on the required list of tables.

in SQL developer go to
Connections     -   Your Connection -   Tables (filter your tables) - Right click - Statistics - Gather Statistics

Run SQL

SELECT *
FROM user_tab_columns t
WHERE
  --t.nullable = 'Y' AND
  t.table_name IN ('Table1','Table2')
AND (t.column_name LIKE '%ORG%'
OR t.column_name LIKE '%BU%')
AND t.num_distinct < 2 ;

Wednesday, October 31, 2018

Knowledge Base: Oracle Financials Basics

Terms:


Company
Legal entity
BU (Operating Unit)
line of business
group account
natural account
Balancing segments
GL accounts
Journal
Set of books

Chart of accounts - General Ledger - Sub Ledger (https://www.business-case-analysis.com/ledger.html#contentslist)

Invoice, payment, Return

Wednesday, October 24, 2018

Knowledge Base: Azure

Azure Basic Training : https://docs.microsoft.com/en-us/learn/paths/azure-fundamentals/

Knowledge Base: Oracle Autonomous datawaerehouise (ADW) ML notebook

Basic Understanding at
https://blogs.oracle.com/datamining/introducing-oracle-machine-learning-sql-notebooks-for-the-oracle-autonomous-data-warehouse-cloud

Details: https://docs.oracle.com/en/cloud/paas/autonomous-data-warehouse-cloud/user/part-using.html#GUID-F9B1D121-5D89-40B4-90C6-8E8E233C2B3F

Troubleshooting:
How to login to a given Schema in notebook
Schema/User need to be given following GRANTS/ROLES to be able to access notebook.
GRANT DWROLE to ;
GRANT OML_DEVELOPER to ;

These Roles can be given by ADMIN user. ADMIN user should connect using SQL Developer or from other client source. (ADMIN user cant run SQL from notebook)
I use a compute machine in the same OCI compartment, then create a connection to ADW.

Knowledge Base: Blockchain

To understand basic cryptocurrency blockchain concept for a beginner.
http://learnmeabitcoin.com/guide/

How is the wallet balance computed
https://bitcoin.stackexchange.com/questions/22997/how-is-a-wallets-balance-computed

https://medium.com/coinmonks/blockchain-for-beginners-what-is-blockchain-519db8c6677a

Thursday, November 23, 2017

Converting a Cooma Seperated List to a 'Oracle DB TABLE TYPE collections'

Here input string is 'Apple,  Orange   ,Mango,Grapes' and output is a table as test_table


create or replace TYPE test_type AS TABLE OF VARCHAR2(100);

DECLARE
test_table test_type;
v_counter INTEGER := 0;
BEGIN
 SELECT ltrim(rtrim(regexp_substr('Apple,  Orange   ,Mango,Grapes','[^,]+',1,level))) regexp_substr
 BULK COLLECT INTO test_table FROM dual CONNECT BY level<=regexp_count('Apple,  Orange   ,Mango,Grapes',',')+1;


--Check the data

FOR i in 1..test2.COUNT
LOOP
SYS.DBMS_OUTPUT.PUT_LINE(test_table(i));
END LOOP;

end;

Tuesday, September 13, 2011

BI Applications: Trees in Peoplesoft Simplified

BI Applications: Trees in Peoplesoft Simplified: Trees in PSFT can be broadly classified into Summer Trees and Winter Trees. I will take the same example of Department for both the cases so...

Friday, August 5, 2011

BI Applications: Resetting the password for SYS User

BI Applications: Resetting the password for SYS User: "Many times we tend to forget the password of the SYS user. In such cases log onto the machine which hosts the DB server and connect as SYSD..."

Friday, April 1, 2011

BI Applications: DB links and Getting DDL from sqlplus

BI Applications: DB links and Getting DDL from sqlplus: "DB link create Syntax - CREATE DATABASE LINK dblink_name CONNECT TO user IDENTIFIED BY pwd USING '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP..."

Wednesday, March 23, 2011

BI Applications: UNSPSC

BI Applications: UNSPSC: "To be frank I had thought UNSPSC to be Unspecified. Later I realized its a standard or a convention used to classify all products and servic..."