cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Azrael1018
Frequent Visitor

PAD Select all cells in a worksheet and copy formatting only to another worksheet

Thank you in advance.

This may be somewhat complex.

I do this every month to 64 worksheets.  Hence my desire to automate.

I have used PAD to download the raw csv of the reports I wish to modify.

e.g. 

Balance sheet raw Screenshot 2022-01-14 162750.jpg

I have a second spreadsheet that I copy formatting from:

Balance sheet formats Screenshot 2022-01-14 162750.jpg

I need to copy the formatting from the second spreadsheet to the first spreadsheet.

When doing manually I Ctrl-A second spreadsheet, switch to first spreadsheet Ctrl-Home and Alt-HVR.

Then I save the first spreadsheet as a .xlsx file.

I will also need to add some blank rows and columns and copy specific cells from second to first but I think I see how to do that.

 

Potentially complicating matters is my second spreadsheet has multiple tabs for formatting the different types of reports.

Balance sheet tabs Screenshot 2022-01-14 162750.jpg

I think I know how to open both spreadsheets in PAD but I am confused how to copy the formatting from one to the other.

 

BTW (another problem), I tried to do it using Recorder. Nothing goes to my flow, as shown below in after "Recording"

Recorder Screenshot 2022-01-14 163937.jpg

I am sure I must be missing something, but I do not know what.

 

Just started with PAD this week.  Already got some relatively complex Web Automation flows done to download these files.  Now I need to process them.

 

Once again, thank you in advance.

David

7 REPLIES 7
MichaelAnnis
Super User
Super User

Hey David,

 

Excel VBA, would be a huge tool here, and much faster than anything PAD can do.  Unfortunately trying to click a cell in PAD takes a VERY long time.  It can do it, but it takes a good 10 seconds, so that's out.  Luckily, the VBA wouldn't even be that complex.

 

We are going to use PAD to get all the filenames, open the Macro workbook, and paste the filenames to A1.  Then, we will use one Macro to loop through all of the files: open the file, extract the type of report from B1 (assuming that is unique - I saw "Balance Sheet"), use a "Select Case" scenario from B1 to determine which tab we want, copy all cells from the tab , paste all formatting to the original file, and save the file where we want; it will do this for every single file.

 

Here is all you need for PAD:

1, get all the files you want to format into a single folder, such as C:\statements to format

2, Use the 'Get files' action to get all files to %Files%

3, Launch the Macro Workbook

4, Run the Macro

 

Done

 

If this is something you are interested in, I can help you build out the VBA Macro, but I want to make sure you are on board, before I spend the time on it.

 

Let me know,

 

Mike

 

Hey Mike,

PAD can be quite slow to click, at least in Web apps.  I converted nearly all of my UI thingamajigs to Mouse Clicks with position.  Thus, I can see what you mean in Excel.

 

I have worked very sparingly with Excel VBA.  Mainly a few simple items using Record Macro.

 

I would happily accept your help.  Can we Direct Message on this board?  Or can you DM me to my email.

 

I did see your reply in my email but did not reply from Gmail as I did not know if I could do so direct to you.

 

Looking forward,

 

David

Here's the Excel VBA if you want to get started before we chat.  

 

I have this set up so your formatting workbook would have another tab called "Files" that PAD would list the files in A1 to A [whatever] which will be defined by "LR" as Last row.  It will find that out on it's own, as long as they are all listed sequentially in column A starting at A1.

 

Your changes are going to be in "get the Case variable from A2 of the opened file"...I think yours is B2, so you will have to point that in the right place.

 

Next change, the "Select Case".  Give each Case for all possible strings found in B2, and each resulting tab name for "formattab".

 

That should be it.  Otherwise, it selects all on the format tab, paste formats on the current file, saves and closes the current file and loops to the next one.

 

Talk to you next week.  Best of luck!

 

Below is the macro code:

 

Sub FormattingWorkbooks()
'
' FormattingWorkbooks Macro
' open each file (listed in Files tab by PAD), identify type of workbook, copy formatting from proper tab, save and close workbook
'

'
Sheets("Files").Select
'get last row to limit the loop run
Dim LR As Long
Range("A1").Select
Selection.End(xlDown).Select
LR = Selection.Row

'dim all variables before loop
Dim filepathandname As String 'the file path and name for the current file in the loop index
Dim formatID As String 'the text identified in the file name used to decide which formatting tab to use
Dim formattab As String 'the formatting tab from the macro workbook to be used to format the current file
Dim AWB As Workbook 'active workbook from filename
Dim i As Integer 'the index for the loop run
i = 1 'the loop will start on A1

'loop for each filename in column A of files (A1 to A & LR)
Do
Sheets("Files").Select
filepathandname = Range("A" & i).Value
Workbooks.Open filename:=filepathandname
'get active workbook name for later window switch after copying cells from macro workbook
Set AWB = ActiveWorkbook

'get the Case variable from A2 of the opened file

formatID = Range("A2").Value
formatID = Trim(formatID) ' removes beginnning or ending spaces off the text
'select which formatting tab we are going to use based on the Case variable
Select Case formatID
Case "UNREALIZED GAINS AND LOSSES"
formattab = "UG"
Case "SECURITY CROSS REFERENCE"
formattab = "SecXRef"
Case Else
MsgBox ("Error - Format not found")
End Select

'copy formatting from format tab
Windows("Copy formatting.xlsm").Activate
Sheets(formattab).Select
Cells.Select
Selection.Copy
Windows(AWB.Name).Activate
Cells.Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Cells.EntireColumn.AutoFit
Application.CutCopyMode = False
ActiveWorkbook.Save
ActiveWindow.Close
Windows("Copy formatting.xlsm").Activate
i = i + 1 'increase i to get the next filename until we reach LR
Loop Until i > LR
End Sub

Benny_1857
Helper III
Helper III

Hello David,

I have the same experience with you. My friend had a lot of heatting analysis data every month and each zip contains a csv file which need to adjust the column. After adjustment, it has 170 columns and 20,000+ rows.

Here is some suggestion I have. Hope will be useful for you.

Here I find several problem you need to solve before you use PAD solve your excel automation.

1. CSV transfer to XLSX
Currently, it is a very easy work to use Excel Power Query. Normally, for PAD could work more easily, you could ask excel get the csv file from folder and PQ will automatically identify the file. 
PQ is a low code tools for data cleaning in excel. From the picture I saw you even do not need to change anything from your csv file. If you need to insert columns or rows that could be adjust in PQ. Just loading after complete PQ adjustment then adjust the font and fill after the loading in excel sheet.

This is an automatic model in excel for your next 63 csv file. Everytime, you just need to load the csv file from this model and save as a new file name.

Benny_1857_0-1642302470006.png

2 loading 64 file. This is why I suggest read the file from folder not file as file have different file name but we could put different csv file into same folder.

You need to have 3 folders. For instance, Folder A is csv Folder which you put 64 csv files in it. Folder C is xlsx folder which you put all completed transferred xlsx file. Folder B is a special one which is for your model to pick up csv file. So everytime, move one csv from A to B, use your PQ model file to read and load it. Then save as to C and clear the folder B at same time. After 64 times, all the csv files in A were moved to B one by one and cleared after transfered to xlsx and save as into C. Finally there only 64 xlsx in C.

(Also, you will need 2 support spreadsheet or excel to load the files name and path in folder A and changed the file name and path to folder C.

Benny_1857_1-1642303421871.png

Benny_1857_2-1642303496409.png

 

 

3. UI automation for Power Query automation. As in Excel, the refresh PQ is mannual, you could use UI automation to start it. Once the PQ completed according to the data size, you could use Image to recognize whether it completed or not to start next step.

4. Small tips, you could google how to remove the refresh link and set up column width

OK.  I think I finally got the PAD working correctly to generate my .csv files.

 

 

I click OK and it continues.  Next I get below.
 

 

I understand this.  It is trying to put it in my Documents folder and I already ran it once, thus producing the file before.
However, I would like it to be put into a specific folder. ???
I click Yes.
 
Then it looks like it goes to the bottom of the file list and gives:
 

 

I click Debug, VBA window opens and I see:
 

 

 
I changed a few things in code.  Hopefully doing it correctly. You had "formatID" defined but had "formattab" in code.  I changed code to formatID.
 

6th unnamed.png

 

 

The Balance sheet did format correctly.  However, it was the only sheet to work.
 
I have a "formatting Worksheet" for each of my nine properties.  I thought if I could get it to work for the first, it will work for the others.
 
Also, there is more things to add to macro.  I have 6 sheets per property.Balance Sheet, Income Statement, Income Statement vs Budget, Income Statement MTM , Statement of cash flows, and GLTB.
On the three Income Statement sheets, I need to insert 5 rows (7-11) and copy 5 rows (7-11) from the formatting sheets. (info on these added rows changes each month dependent on another workbook).
Complicating things further, the MTM I copy A7-A10 and then C7-M10 (drop off oldest month), then copy L7-L10 (old M7-M10) to M7 so newest month number can be put in.
 
To complicate even further, 4 of the properties the above works (7-11, etc), but 5 of the properties download differently. Instead of 7-11, I must insert, copy etc from 9-13.
 
Complex? Yes.  Incredible amount of time saving, though, once I can get it work.
 
Below is my VBA as it stands now:

Sub FormattingWorkbooks()
'
' FormattingWorkbooks Macro
' open each file (listed in Files tab by PAD), identify type of workbook, copy formatting from proper tab, save and close workbook
'

'
Sheets("Files").Select
'get last row to limit the loop run
Dim LR As Long
Range("A1").Select
Selection.End(xlDown).Select
LR = Selection.Row

'dim all variables before loop
Dim filepathandname As String 'the file path and name for the current file in the loop index
Dim formatID As String 'the text identified in the file name used to decide which formatting tab to use
Dim formattab As String 'the formatting tab from the macro workbook to be used to format the current file
Dim AWB As Workbook 'active workbook from filename
Dim i As Integer 'the index for the loop run
i = 1 'the loop will start on A1

'loop for each filename in column A of files (A1 to A & LR)
Do
Sheets("Files").Select
filepathandname = Range("A" & i).Value
Workbooks.Open Filename:=filepathandname
'get active workbook name for later window switch after copying cells from macro workbook
Set AWB = ActiveWorkbook

'get the Case variable from A2 of the opened file

formatID = Range("B2").Value
formatID = Trim(formatID) ' removes beginnning or ending spaces off the text
'select which formatting tab we are going to use based on the Case variable
Select Case formatID
Case "Balance Sheet"
formattab = "Balance Sheet"
Case "INCOME STATEMENT"
formattab = "Inc Stmnt"
Case "INCOME STATEMENT vs Budget"
formattab = "Inc Stmnt vs Budget"
Case "INCOME STATEMENT MTM"
formattab = "Inc Stmnt MTM"
Case "STATEMENT OF CASHFLOWS - IB"
formattab = "St Cash Flows"
Case "Account Number"
formattab = "GLTB"
Case Else
MsgBox ("Error - Format not found")
End Select

'copy formatting from format tab
Windows("Copy formatting.xlsm").Activate
Sheets(formattab).Select
Cells.Select
Selection.Copy
Windows(AWB.Name).Activate
Cells.Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Cells.EntireColumn.AutoFit
Application.CutCopyMode = False
ActiveWorkbook.SaveAs , FileFormat:=51
ActiveWindow.Close
Windows("Copy formatting.xlsm").Activate
i = i + 1 'increase i to get the next filename until we reach LR
Loop Until i > LR
End Sub

 

 
Thank you,
 
David
 

Sorry, I cannot get pics to upload.

first above is a Microsoft excel Error box:

Error - Format not found

 

Second is reference Microsoft sheet already exits.

 

3rd missing after "file list and gives"

MS VBA 

Run-time error '9':

Subscript out of range

 

4th missing "open and I see"

'copy formatting from format tab
Windows("Altoona Worksheet Template.xlsx").Activate
Sheets(formatID).Select  
Cells.Select
Selection.Copy
Windows(AWB.Name).Activate

Ok, let’s set up a time later this week.  I sent you a PM and we can go through it on zoom. I was not able to read everything, but formatID was what you see and formattab was the resulting tab you get. 

select case [variable to iterate]
    Case [variable is]
    Result

End Select

Helpful resources

Announcements

Power Platform Connections - Episode 7 | March 30, 2023

Episode Seven of Power Platform Connections sees David Warner and Hugo Bernier talk to Microsoft MVP Dian Taylor, alongside the latest news, product reviews, and community blogs.     Use the hashtag #PowerPlatformConnects on social media for a chance to have your work featured on the show!      Show schedule in this episode:    0:00 Cold Open 00:30 Show Intro 01:02 Dian Taylor Interview 18:03 Blogs & Articles 26:55 Outro & Bloopers    Check out the blogs and articles featured in this week’s episode:    https://francomusso.com/create-a-drag-and-drop-experience-to-upload-case-attachments @crmbizcoach https://www.youtube.com/watch?v=G3522H834Ro​/  @pranavkhuranauk https://github.com/pnp/powerapps-designtoolkit/tree/main/materialdesign%20components @MMe2K​ https://2die4it.com/2023/03/27/populate-a-dynamic-microsoft-word-template-in-power-automate-flow/ @StefanS365 https://d365goddess.com/viva-sales-administrator-settings/ @D365Goddess https://marketplace.visualstudio.com/items?itemName=megel.mme2k-powerapps-helper#Visualize_Dataverse_Environments @MMe2K    Action requested:  Feel free to provide feedback on how we can make our community more inclusive and diverse.    This episode premiered live on our YouTube at 12pm PST on Thursday 30th March 2023.    Video series available at Power Platform Community YouTube channel.    Upcoming events:  Business Applications Launch – April 4th – Free and Virtual! M365 Conference - May 1-5th - Las Vegas Power Apps Developers Summit – May 19-20th - London European Power Platform conference – Jun. 20-22nd - Dublin Microsoft Power Platform Conference – Oct. 3-5th - Las Vegas    Join our Communities:  Power Apps Community Power Automate Community Power Virtual Agents Community Power Pages Community    If you’d like to hear from a specific community member in an upcoming recording and/or have specific questions for the Power Platform Connections team, please let us know. We will do our best to address all your requests or questions.       

Announcing | Super Users - 2023 Season 1

Super Users – 2023 Season 1    We are excited to kick off the Power Users Super User Program for 2023 - Season 1.  The Power Platform Super Users have done an amazing job in keeping the Power Platform communities helpful, accurate and responsive. We would like to send these amazing folks a big THANK YOU for their efforts.      Super User Season 1 | Contributions July 1, 2022 – December 31, 2022  Super User Season 2 | Contributions January 1, 2023 – June 30, 2023    Curious what a Super User is? Super Users are especially active community members who are eager to help others with their community questions. There are 2 Super User seasons in a year, and we monitor the community for new potential Super Users at the end of each season. Super Users are recognized in the community with both a rank name and icon next to their username, and a seasonal badge on their profile.  Power Apps  Power Automate  Power Virtual Agents  Power Pages  Pstork1*  Pstork1*  Pstork1*  OliverRodrigues  BCBuizer  Expiscornovus*  Expiscornovus*  ragavanrajan  AhmedSalih  grantjenkins  renatoromao    Mira_Ghaly*  Mira_Ghaly*      Sundeep_Malik*  Sundeep_Malik*      SudeepGhatakNZ*  SudeepGhatakNZ*      StretchFredrik*  StretchFredrik*      365-Assist*  365-Assist*      cha_cha  ekarim2020      timl  Hardesh15      iAm_ManCat  annajhaveri      SebS  Rhiassuring      LaurensM  abm      TheRobRush  Ankesh_49      WiZey  lbendlin      Nogueira1306  Kaif_Siddique      victorcp  RobElliott      dpoggemann  srduval      SBax  CFernandes      Roverandom  schwibach      Akser  CraigStewart      PowerRanger  MichaelAnnis      subsguts  David_MA      EricRegnier  edgonzales      zmansuri  GeorgiosG      ChrisPiasecki  ryule      AmDev  fchopo      phipps0218  tom_riha      theapurva  takolota     Akash17  momlo     BCLS776  Shuvam-rpa     rampprakash  ScottShearer     Rusk  ChristianAbata     cchannon  Koen5     a33ik  Heartholme     AaronKnox  okeks      Matren   David_MA     Alex_10        Jeff_Thorpe        poweractivate        Ramole        DianaBirkelbach        DavidZoon        AJ_Z        PriyankaGeethik        BrianS        StalinPonnusamy        HamidBee        CNT        Anonymous_Hippo        Anchov        KeithAtherton        alaabitar        Tolu_Victor        KRider        sperry1625        IPC_ahaas      zuurg    rubin_boer   cwebb365   Dorrinda   G1124   Gabibalaban   Manan-Malhotra   jcfDaniel   WarrenBelz   Waegemma   drrickryp   GuidoPreite    If an * is at the end of a user's name this means they are a Multi Super User, in more than one community. Please note this is not the final list, as we are pending a few acceptances.  Once they are received the list will be updated. 

Register now for the Business Applications Launch Event | Tuesday, April 4, 2023

Join us for an in-depth look into the latest updates across Microsoft Dynamics 365 and Microsoft Power Platform that are helping businesses overcome their biggest challenges today.   Find out about new features, capabilities, and best practices for connecting data to deliver exceptional customer experiences, collaborating, and creating using AI-powered capabilities, driving productivity with automation—and building towards future growth with today’s leading technology.   Microsoft leaders and experts will guide you through the full 2023 release wave 1 and how these advancements will help you: Expand visibility, reduce time, and enhance creativity in your departments and teams with unified, AI-powered capabilities.Empower your employees to focus on revenue-generating tasks while automating repetitive tasks.Connect people, data, and processes across your organization with modern collaboration tools.Innovate without limits using the latest in low-code development, including new GPT-powered capabilities.    Click Here to Register Today!    

Check out the new Power Platform Communities Front Door Experience!

We are excited to share the ‘Power Platform Communities Front Door’ experience with you!   Front Door brings together content from all the Power Platform communities into a single place for our community members, customers and low-code, no-code enthusiasts to learn, share and engage with peers, advocates, community program managers and our product team members. There are a host of features and new capabilities now available on Power Platform Communities Front Door to make content more discoverable for all power product community users which includes ForumsUser GroupsEventsCommunity highlightsCommunity by numbersLinks to all communities Users can see top discussions from across all the Power Platform communities and easily navigate to the latest or trending posts for further interaction. Additionally, they can filter to individual products as well.   Users can filter and browse the user group events from all power platform products with feature parity to existing community user group experience and added filtering capabilities.     Users can now explore user groups on the Power Platform Front Door landing page with capability to view all products in Power Platform.      Explore Power Platform Communities Front Door today. Visit Power Platform Community Front door to easily navigate to the different product communities, view a roll up of user groups, events and forums.

Microsoft Power Platform Conference | Registration Open | Oct. 3-5 2023

We are so excited to see you for the Microsoft Power Platform Conference in Las Vegas October 3-5 2023! But first, let's take a look back at some fun moments and the best community in tech from MPPC 2022 in Orlando, Florida.   Featuring guest speakers such as Charles Lamanna, Heather Cook, Julie Strauss, Nirav Shah, Ryan Cunningham, Sangya Singh, Stephen Siciliano, Hugo Bernier and many more.   Register today: https://www.powerplatformconf.com/   

Users online (1,619)