Help with Loop

Roller

Board Regular
Joined
Jan 31, 2005
Messages
113
Hello all, I am looking for some guidance for performing a loop to essentially concatenate data from a range of cells into an output file. I have written code that writes (exports) a *.txt file for all data entered into worksheet. Each row of data is a separate check payment to various vendors so the data is very simple: Name, address, check amount, and data from the invoice. The limitation with what I've built is each row is a single payment record and the macro writes each row into the *.txt file in the same order it was input into the worksheet.

I want to expand the use of this worksheet to provide the users of this worksheet to add multiple invoices to a single payment. Functionally, the user just adds the necessary data in the corresponding columns for the data they are adding while leaving the other fields (i.e. name, address, amount) blank. If I use check number as the key field that links the records together, how can I perform a loop for to count the number of times the check number field is the same so I can use the loop to concatenate the data fields and then move on to the next payment. Each payment can have 0 additional records or up to 2400 (unlikely but that is the system max).
I have a constraint that all this data must be concatenated in the output file.

I cannot seem to identify how many additional records are present for a given payment. I plan to use this variable amount in the .offset( ) to get the correct cell reference. Thanks in advance for your consideration.
 
Then you must explain how your data is, with the example data that I put in post #6 generate a file.

Use XL2BB tool to display an example data.

1588685871320.png

1588685899239.png
 

Attachments

  • 1588685856387.png
    1588685856387.png
    21 KB · Views: 2
  • 1588685889816.png
    1588685889816.png
    17.2 KB · Views: 3
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi Dante Amor - Sorry for the delayed response... (Shifting priorities at work)… Anyway, I have tried your code and am still getting a blank file when running your macro. Here is my data
INPAlternateCheckIssuance v060220.xlsm
BCDEFGHIJKLMNTUVWX
1Check No.Payee Name 1Payee Name 2 [optional]Check DateAmountAccountMail MethodAddress Line1Address Line2CityState or ProvinceZipCountryRemit 1 EG: Invoice #Remit 2 EG: Invoice DtRemit 3 EG: Inv AmountRemit 4 EG: DiscountRemit 5 EG: Description
2123456ABC Company5/28/20202,500.00 1851812345US1234 Street DrSuite 1ALos AngelesCA90200US555-asdf205/01/201500.000.00Smith
3123456556-asdf205/08/20500.000.00Jenkins
4123456557-asdf205/15/20500.000.00Roberts
5123457XYZ Company5/28/2020500.00 1851812345US333 Main St.Rm 222bDetroitMI48101US564887204/30/20600.00100.00Requisition
6123458PQS Incorporated5/28/20201,000.00 1851812345USP.O. Box 23456DallasTX66110US33211004/30/20200.000.00Reimbursement
712345833208703/31/20800.000.00Q1 941
CheckDataInput
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C2:C7Expression=LEN($C2)<=ReferenceTab!$G$4textNO
L2:L7Expression=IF($N2="US",AND(ISBLANK($L2)=FALSE,LEN($L2)=2),LEN($L2)<=ReferenceTab!$G$13)textNO
N2:N7Expression=N2=LOOKUP(N2,CountryCode)textNO
M2:M7Expression=OR(LEN(M2)=5,LEN(M2)=9,AND(LEN(M2)=10,IFERROR(FIND("-",M2,1)=6,LEN(M2))))textNO
K2:K7Expression=AND(ISBLANK(K2)=FALSE,LEN(K2)<=ReferenceTab!$G$12)textNO
J2:J7Expression=AND(ISBLANK(B2)=FALSE,LEN(J2)<=ReferenceTab!$G$11)textNO
I2:I7Expression=AND(ISBLANK(I2)=FALSE,LEN(I2)<=ReferenceTab!$G$10)textNO
H2:H7Expression=OR(H2="US",H2="OV",H2="BBUS",H2="BBOV",H2="BB2D")textNO
F2:F7Expression=ISNUMBER(F2)textNO
E2:E7Expression=AND(E2>=TODAY(),E2<=TODAY()+30)textNO
D2:D7Expression=AND(ISBLANK(B2)=FALSE,LEN(D2)<=ReferenceTab!$G$5)textNO
B2:B7Expression=AND(LEN(B2)<=ReferenceTab!$G$3)textNO
Cells with Data Validation
CellAllowCriteria
G2:G7List=AccountList
H2:H7ListUS,OV,BBUS,BBOV,BB2D
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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