Modify Code

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
779
Office Version
  1. 365
Hi

I have this code:

VBA Code:
Sub ImportRawData()

    Dim c           As Long
    Dim Col         As Variant
    Dim Filename    As String
    Dim Filepath    As Variant
    Dim rngBeg      As Range
    Dim rngEnd      As Range
    Dim rngDst      As Range
    Dim rngSrc      As Range
    Dim rowsize     As Long
    Dim wkbDst      As Workbook
    Dim wkbSrc      As Workbook
    
        Set wkbDst = ThisWorkbook
        Set rngDst = wkbDst.Worksheets("EFT").Range("A4:E4")
        
        Filepath = "C:\Users\jose.rossi\Desktop\NCL EFT_Summary.xlsm"
        Filename = "apcbtclz.csv"
        
        On Error Resume Next
            Set wkbSrc = Workbooks(Filename)
            If Err = 9 Then
                If Filepath <> "" Then ChDir Filepath Else ChDir ThisWorkbook.Path
                Filename = Application.GetOpenFilename("Excel Workbooks, *.xlsx")
                If Filename = "False" Then Exit Sub
                Set wkbSrc = Workbooks.Open(Filename)
            End If
        On Error GoTo 0
        
        ' Clear previous data.
        rngDst.Resize(rngDst.Parent.UsedRange.Rows.Count).ClearContents
        
        ' Import the data.
        With wkbSrc.Worksheets("apcbtclz").UsedRange
            ' Step through the source data columns.
            For Each Col In Array("AW", "BO", "BB", "AX", "X")
                ' Data starts on row 1.
                Set rngBeg = .Parent.Cells(1, Col)
                
                ' Find the row where the data ends in this column.
                Set rngEnd = .Parent.Cells(Rows.Count, Col).End(xlUp)
                
                ' Number of rows in this column.
                rowsize = rngEnd.Row '- rngBeg.Row
                
                If rowsize > 0 Then
                    Set rngSrc = .Parent.Range(rngBeg, rngEnd)
                    rngDst.Offset(0, c).Resize(rowsize, 1).Value = rngSrc.Value
                End If
                
                ' Increment the column offset.
                c = c + 1
            Next Col
        End With
        
End Sub

Question:

If possible in this line:

VBA Code:
For Each Col In Array("AW", "BO", "BB", "AX", "X")


The

VBA Code:
"AX"

column has the name of the director approving the invoice but if the row is blank how to modify the the code to add the word "Recurring" when blank.

Thank you,
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
This is a lot of code for copying a five (5) of columns from one book to another. For instance if you know that the source data starts on row 1 why do you have to set that to a Range object. Your ranges are always going to start at AW1, BO1, BB1, etc. What kind of data is in your columns, are they values, formulas, or both. When you are clearing the data in UsedRange on the Destination Sheet, does that effectively clear all the data on the sheet or is there other data in some other areas that are not part of the used range. If "c' starts at zero then you are writing to columns A:E. Is it just those columns that you are clearing.

Maybe I am missing something but IMHO you sure are making this harder than it needs to be.
 
Upvote 0
Hi,

Actually they are all values and just want column "AX" when is blank to enter the word Recurring.

to be hones I found this code online and no that good in VBA so just made the changes I know.
other problem I am having that this is a template and I have total formula but when the data is imported is deleting my total formula.

thank you,
 
Upvote 0
Except for the top half of the code that is checking for the correct Workbooks. If you could explain exactly what you want to accomplish (including the workbook names and sheet name), we could fix the code up to do what is required. If you could post some before and after data (real or fictitious) that would go a long way.

Also if you could update your profile information to reflect your Office Version and Platform, it would be a help to everyone who reads this and future posts.
 
Upvote 0
Hi,

Here what I would like if possible any of the points below:

1. Inserting images of before/after and image of the data being imported from: both file that am using:

2. is it possible that change these vba lines no to check for the file name and sheet name:
With wkbSrc.Worksheets("apcbtclz").UsedRange

With wkbSrc.Worksheets("apcbtclz").UsedRange

(because the accounting software rename the file every time it prints it by adding a number at the end, to for example first print out file name will be " apcbtclz" but after will name it apcbtclz1, and so on. so in order the macros to work we need to save the the file and sheet name to this "apcbtclz" otherwise won't work.

3. the Column "AX" has the approval name of the director approving the invoice(s) to pay and I would like that when that field (row) is empty or blank to insert the word "Recurring".

4. In the template I have to import the data (by the way the file/sheet name never change) the problem having is that I have grand total formula at the end as you can see in the images but when data gets imported the formula will be deleted just wonder if there's a way formula will stay..

much appreciated your help.

is there anyway I can attach the files instead of images?

thank you,
 

Attachments

  • BEFORE IMPORTING.PNG
    BEFORE IMPORTING.PNG
    11.4 KB · Views: 7
  • AFTER IMPORTING.PNG
    AFTER IMPORTING.PNG
    31 KB · Views: 6
  • file data being imported from (partial).PNG
    file data being imported from (partial).PNG
    40.5 KB · Views: 7
Upvote 0
Here the before mini sheet and after and also the file that importing from:

WONDERFUL CO. EFT_Summary.xlsm
ABCDEF
3Sl #Name Amount ApprovalPayment batch Remarks
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22GRAND TOTAL =================>>$ -
EFT
Cell Formulas
RangeFormula
C22C22=SUM(TOTAL)
Named Ranges
NameRefers ToCells
TOTAL=EFT!$C$4:$C$21C22
Cells with Data Validation
CellAllowCriteria
B4List=EFT



WONDERFUL CO. EFT_Summary.xlsm
ABCDEF
3Sl #Name Amount ApprovalPayment batch Remarks
41Bell $ 491.62Luis Lopez222
52CANADA BOXING$ 17,672.31Regular service222
63Front Line$ 6,412.75Daniel Voug222
74IMPARK$ 845.66Walter Larus222
85LIVINGSTON INC$ 239.18Paul Smith222
96David Wong$ 691.71Walter Larus222
107Lawrence Leiu$ 235.82Roger Swift222
118Denis Seger$ 701.50Rob Switz/Kelly Sterling222
129MDM BUSINESS SOLUTIONS$ 256.23Rob Switz/Kelly Sterling222
1310Mills Imported$ 2,999.92Shaun Ruiz/Juan Y/Susan Lopez222
1411Pics$ 23,399.83Don Grand222
1512UPS$ 3,409.32William Atz/Gerry S222
16
17
18
19
20
21
22
EFT
Cells with Data Validation
CellAllowCriteria
B4List=EFT



apcbtclz.csv
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABBBCBDBEBFBGBHBIBJBKBLBMBNBOBPBQ
12021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2800No. of Checks Printed:0Entry No.:1Luis LopezDocument No.:PY04560Payment Amt. (CAD):491.62Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:BELL1691Bell Account Set:APGEN
22021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2801No. of Checks Printed:0Entry No.:2Regular serviceDocument No.:PY04561Payment Amt. (CAD):17,672.31Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:CANPOSTCANADA BOXINGAccount Set:APGEN
32021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2802No. of Checks Printed:0Entry No.:3Daniel VougDocument No.:PY04562Payment Amt. (CAD):6,412.75Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:FROLINFront LineAccount Set:APGEN
42021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2803No. of Checks Printed:0Entry No.:4Walter LarusDocument No.:PY04563Payment Amt. (CAD):845.66Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:IMPARKIMPARKAccount Set:APGEN
52021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2804No. of Checks Printed:0Entry No.:5Paul SmithDocument No.:PY04564Payment Amt. (CAD):239.18Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:LIVINGLIVINGSTON INCAccount Set:APGEN
62021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2805No. of Checks Printed:0Entry No.:6Walter LarusDocument No.:PY04565Payment Amt. (CAD):691.71Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:CHOODDavid WongAccount Set:APGEN
72021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2806No. of Checks Printed:0Entry No.:7Roger SwiftDocument No.:PY04566Payment Amt. (CAD):235.82Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:ROBILLawrence LeiuAccount Set:APGEN
82021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2807No. of Checks Printed:0Entry No.:8Rob Switz/Kelly SterlingDocument No.:PY04567Payment Amt. (CAD):701.5Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:LEGERDenis SegerAccount Set:APGEN
92021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2808No. of Checks Printed:0Entry No.:9Rob Switz/Kelly SterlingDocument No.:PY04568Payment Amt. (CAD):256.23Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:MDM BUMDM BUSINESS SOLUTIONSAccount Set:APGEN
102021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2809No. of Checks Printed:0Entry No.:10Shaun Ruiz/Juan Y/Susan LopezDocument No.:PY04569Payment Amt. (CAD):2,999.92Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:MICROSMills ImportedAccount Set:APGEN
112021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2810No. of Checks Printed:0Entry No.:11Don GrandDocument No.:PY04570Payment Amt. (CAD):23,399.83Transaction Type:PaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:PICSCADPicsAccount Set:APGEN
122021-07-30 6:37:14PMwonderful companyPage 1A/P Batch Listing - Payment (APCBTCLZ)From Batch Number[222] To [222]From Batch Date[2021-08-03] To [2021-08-03]Type[Entered, Imported, Generated, System, External]Status[Open, Ready To Post, Posted]Reprint Previously Printed Batches [Yes]Show Tax Details[Yes]Show Adjustment Details[Yes]Show Optional Fields[Yes]Batch No.:222Description:EFT Wonderful Company August 03, 2021 RA-JRCurrency:CADTotal Amount:57,355.85Batch Date:8/3/2021Type:EnteredSource Application:APNo. of Entries:12Last Edited:########Status:OpenBank:BMO2811No. of Checks Printed:0Entry No.:12William Atz/Gerry SDocument No.:PY04571Payment Amt. (CAD):3,409.32Transaction Type:PrepaymentPayment Date:8/3/2021Posting Date:8/3/2021Year - Period:21-AugVendor:UPS CAUPSAccount Set:APGEN
apcbtclz



I also update the profile with office 365

thank you
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top