Solved

excel vba

Posted on 2014-09-22
5
252 Views
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.
 



Sheets("Main").Select
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
    DoEvents

Open in new window

0
Comment
Question by:ProfessorJimJam
  • 3
  • 2
5 Comments
 
LVL 31

Accepted Solution

by:
Rob Henson earned 500 total points
Comment Utility
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"")"

Thanks
Rob H
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
Syntax:

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

Author Comment

by:ProfessorJimJam
Comment Utility
yes. it could be LastRow = Cells(Rows.Count, 1).End(xlUp).Row
0
 
LVL 25

Author Comment

by:ProfessorJimJam
Comment Utility
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?
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
Sorry, don't know anything about immediate window.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now