Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


excel vba

Posted on 2014-09-22
Medium Priority
Last Modified: 2014-09-23
currently this code works via doevent, the problem is if there is blank cell in column A then it stop there, however the even if there is a blank cell , the last row is down further. i want this code so that it works to the last row that has data.

second problem is the ",[DATA.xlsx]File!$C$2:$C$51 and ",[DATA.xlsx]File!$E$2:$E$51 you can see the it looks up to 51 rows in the next sheet and it is not dynamic too. i want this also to look at the last row instead of 51.

introw = 2
Do Until Cells(introw, 1) = ""
    Cells(introw, 1) = Trim(Cells(introw, 1))
    Cells(introw, 2) = Trim(Cells(introw, 2))
    Cells(introw, 10).FormulaArray = "=IFERROR(INDEX([DATA.xlsx]File!$C$2:$C$51,MATCH($B" & introw & "&$A" & introw & ",[DATA.xlsx]File!$C$2:$C$51&[DATA.xlsx]File!$E$2:$E$51,0)),""Not Found"")"
    Cells(introw, 11).FormulaArray = "=IFERROR(INDEX([DATA.xlsx]File!$E$2:$E$51,MATCH($B" & introw & "&$A" & introw & ",[DATA.xlsx]File!$C$2:$C$51&[DATA.xlsx]File!$E$2:$E$51,0)),""Not Found"")"
    Cells(introw, 12).FormulaArray = "=IFERROR(INDEX([DATA.xlsx]File!$G$2:$G$51,MATCH($B" & introw & "&$A" & introw & ",[DATA.xlsx]File!$C$2:$C$51&[DATA.xlsx]File!$E$2:$E$51,0)),""Not Found"")"
    Cells(introw, 13).FormulaArray = "=IFERROR(INDEX([DATA.xlsx]File!$L$2:$L$51,MATCH($B" & introw & "&$A" & introw & ",[DATA.xlsx]File!$C$2:$C$51&[DATA.xlsx]File!$E$2:$E$51,0)),""Not Found"")"
    Range(Cells(introw, 10), Cells(introw, 13)).Formula = Range(Cells(introw, 10), Cells(introw, 13)).Value
    introw = introw + 1

Open in new window

Question by:ProfessorJimJam
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
  • 3
  • 2
LVL 33

Accepted Solution

Rob Henson earned 2000 total points
ID: 40336757
You can discover the last row by selecting A1048576 and then doing an xlEndUp.

There is a way of doing it without selecting first but I can't recall the syntax.

You could use this command to discover the last row in both files and then set them to two variables (lastrow1 & lastrow2)to use within the routine.

Your Do Until would then be

Do Until introw = lastrow1

Your array formulas would then be:

Cells(introw, 10).FormulaArray = "=IFERROR(INDEX([DATA.xlsx]File!$C$2:$C$"&lastrow2&",MATCH($B" & introw & "&$A" & introw & ",[DATA.xlsx]File!$C$2:$C$"&lastrow2&"&[DATA.xlsx]File!$E$2:$E$"&lastrow2&",0)),""Not Found"")"

Rob H
LVL 33

Expert Comment

by:Rob Henson
ID: 40336775

LastRow = Range("A1048576", Selection.End(xlUp)).Row
LVL 27

Author Comment

ID: 40336937
yes. it could be LastRow = Cells(Rows.Count, 1).End(xlUp).Row
LVL 27

Author Comment

ID: 40336944
my immediate window does not work. any idea why it was working before but after running the macro once it does not return any information.

when i put print introw   nothing returns
also i tried  with ?introw

suddenly it stopped working.  is there somthign i did wrong?
LVL 33

Expert Comment

by:Rob Henson
ID: 40338574
Sorry, don't know anything about immediate window.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
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…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

670 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