Wednesday, May 4, 2022

Creating your own function in Excel

 Excel VBA function to create a delimited file

I use this if I have a spreadsheet of values in a row of cells and I want to turn that row into something I can use as a text import file. This article walks you through how to create a custom Excel function named CREATE_DELIMITED.

Let’s say we start with a spreadsheet similar to the one below. If you want to follow along, create a similar spreadsheet with a few rows of data. We want to turn this into a bar (|) delimited text file that we can use in a table import.

 



To accomplish this, we are going to produce the CREATE_DELIMITED custom function in this workbook. Later we will add it as an Excel add-in so it will be available to any workbook.

 

Follow these steps to create the function:

1.    Open a new blank workbook.

2.    Press Alt+F11 to open the Visual Basic Editor, and then click Insert > Module.  A new module window appears on the right-hand side of the Visual Basic Editor.

3.    Copy and paste the following code into the new module

 

'Custom Function to join a range of cells together with an optional delimiter

 

Function CREATE_DELIMITED(ByVal cellRange As Range, Optional ByVal delimiter As String)

 Dim c As Range

 Dim DelimitedText As String

 Dim Count As Integer

 Count = 0

 DelimitedText = ""

 For Each c In cellRange

  Count = Count + 1

  DelimitedText = DelimitedText & c.Value

  If Count < cellRange.Count Then

   DelimitedText = DelimitedText & delimiter

  End If

 Next

 CREATE_DELIMITED = DelimitedText

End Function


 

Using custom functions

 Now you’re ready to use the CREATE_DELIMITED function that you just produced. Close the Visual Basic Editor and select cell A14 and type one of the following:

 For a bar (|) delimited file, use this:

=CREATE_DELIMITED(A2:G2,"|")

It will produce this:

10599|MICLINK|Alesis MicLink AudioLink Series XLR-to-USB Cable|36|27|79|2

------------------------------------------------------------------------------------------------------

For a quote delimited file separated with commas, use this:

=""""&CREATE_DELIMITED(A2:G2,""",""")&""""

 It will produce this:

 "10599","MICLINK","Alesis MicLink AudioLink Series XLR-to-USB Cable","36","27","79","2"

------------------------------------------------------------------------------------------------------

For a comma delimited file use this:

=CREATE_DELIMITED(A2:G2,",")

 It will produce this:

10599,MICLINK,Alesis MicLink AudioLink Series XLR-to-USB Cable,36,27,79,2

------------------------------------------------------------------------------------------------------

 

Creating the Add-in

To make this function available to any workbook, delete all of the data on the worksheet and save the file as an Excel Add-In.

 


Accept the location that Excel suggests, name the file something descriptive. I saved mine as CREATE_DELIMITED (so original, I know).

Select the Developer tab from your toolbar (you may have to add this, it doesn’t appear automatically). Then select Excel Add-Ins. Your list of add-ins appears, just check the one that contains your CREATE_DELIMITED function and you’re good to go.

 

Now you should be able to use this function in any workbook you create. If you don’t see it, check the Excel Add-ins toolbar item to make sure the Add-in is marked.

 

Until next time!

Leslie

Tuesday, March 27, 2018

Setting a New Default Checkbook

So, you’ve changed banks and opened a new account. Now it’s time to create a new checkbook in GP and assign it as the default Checkbook ID. No problem, you’ve got this:

  1. Create a New GL Account
  2. Create a New Checkbook ID
  3. Assign the new Checkbook as the default.

This is where the trouble starts. Where in the world can you set the default company Checkbook ID? The truth is, there is no single place to set the default Checkbook ID. You need to set it in several places if you want to use the same checkbook for all of the modules. Each of the following modules has a default checkbook setting.

  • Payables Management
    • Purchasing | Setup | Payables
    • Payables Setup
  • Receivables Management
    • Sales | Setup | Receivables
    • Receivables Setup
  • Sales Order Processing
    • Sales | Setup | Sales Order Processing
    • SOP Setup
  • Payroll
    • HR & Payroll | Setup | Payroll | Payroll
    • payroll setup
  • Bank Reconciliation
    • Financial | Setup | Financial | Bank Reconciliation
    • Bank Rec Setup

Now, you need to check to see if you have any checkbook default identified on the Vendor card or Customer card. When processing a receivables or SOP transaction, GP will look for a checkbook ID at the customer card first. If it doesn’t find one there, it will look to the Receivables Management Setup window or the Sales Order Processing Setup window, depending on what kind of transaction you are entering. For payables, it will look first to the Vendor card and then to the Payables Setup window.

You should never have the same Checkbook ID on a card that you have on the setup window. Let the program do the work for you. Only put a separate Checkbook ID at the card level if you have an exception from your usual checking account.

If you find that you do have a Checkbook ID set on the cards and want to remove it, you can use the Class ID to remove it and then roll down the changes. If you have too many classes to do it manually, or no classes at all, you can use SQL to remove the Checkbook IDs. Your update statements would look similar to those below if you wanted to remove them all.

For Vendors:
UPDATE PM00200 SET CHEKBKID = ''

For Customers:
UPDATE RM00101 SET CHEKBKID = ''

If you are using a third-party product such as Mekorma MICR or BGE Green Payable there will be other places where you’ll need to change the default. Take a look at the setup screens for any add-on products you are using and look for a Checkbook ID setting.

If you find some other places where the Checkbook ID may need to be changed, please leave a comment and I’ll include it in the body of the post.

Live the dream!

Leslie

Sunday, January 7, 2018

Modified Form 1099 Misc. and the ‘1099s Printed’ report

While preparing our annual 1099s, we had the need to change the name on the 1099 from the Vendor Check Name to an individual’s name. We use the name and social that match the name of the sole proprietor. While the new(ish) field on the Vendor Maintenance window for the address code used on the 1099 is a good start, it doesn’t let you change the Name field that prints on the 1099. Regardless of the Address Code selected, the Vendor Check Name is used by GP to set the name appearing on the 1099.

Oddly, the Vendor Name is used on the ‘1099s Printed’ report instead of the Vendor Check Name.

How the modification works is this. If you need to change the name, use the Address Code of ‘1099’ as the 1099 Address Code. The system will look at the 1099 Address code and if it is ‘1099’ then the Vendor Contact Name is used on the 1099, otherwise the Vendor Check Name is used.

If you would like a copy of these modified reports, you can download the package file from HERE.

Live the dream!

Leslie