Solved

excel vba

Posted on 2014-09-22
5
253 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 32

Accepted Solution

by:
Rob Henson earned 500 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 32

Expert Comment

by:Rob Henson
ID: 40336775
Syntax:

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

Author Comment

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

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 32

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

895 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

15 Experts available now in Live!

Get 1:1 Help Now