Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

excel vba

Posted on 2014-09-22
5
Medium Priority
?
263 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 34

Accepted Solution

by:
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"")"

Thanks
Rob H
0
 
LVL 34

Expert Comment

by:Rob Henson
ID: 40336775
Syntax:

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

Author Comment

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

Author Comment

by:ProfessorJimJam
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?
0
 
LVL 34

Expert Comment

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

782 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