Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add additional vba code to existing macro

Posted on 2014-04-10
2
Medium Priority
?
350 Views
Last Modified: 2014-04-11
Hi Experts,

I have an existing macro that formats an excel spreadsheet into fixed width text file based on customer specs.

I need to add code to enter ZZ into dl_state column if driver lives in foreign country, except if it is Canada.   For Canada the province code gets entered into the dl_state column for all provinces except Northwest Territories and Yukon.    These get a ZZ.

What is best approach for this?  I've attached spreadsheet with data(dummy data)  and the macro.  
Thanks.
afftest.txt
DataTest.xls
0
Comment
Question by:rhadash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 39992924
Find the loop where you applied the XX, replace it with this:

'Range("c1") = "Filler"


For i = 2 To lastRow

    If Len(Cells(i, "I").Text) < 2 Then
        Cells(i, "I").Value = "ZZ"
    End If
    If Sheets("CHI").Cells(i, "W").Value <> "CA" Then
        Cells(i, "I").Value = "ZZ"
    Else
        If Sheets("CHI").Cells(i, "U").Value = "NT" Or Sheets("CHI").Cells(i, "U").Value = "YT" Then
            Cells(i, "I").Value = "ZZ"
        Else
            Cells(i, "I").Value = Sheets("CHI").Cells(i, "U").Value
        End If
    End If

Next i

Open in new window

0
 

Author Closing Comment

by:rhadash
ID: 39994690
Thanks.  You have provided the basic structure required to make this work.  I've been able to adjust to meet requirements.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
MS Access 2003 or later To MySQL Migration Project Hello All, this is my second article in the category of MS-OFFICE Automation. In internet I am not able to find any comprehensive resource on the Migration of MS Access back-end to MySQL so I fin…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question