Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default End process at last row of data

I have the following, which works but it continues all the way down the column and I need it to end at the last row of data in Column A and not keep running...

The next question I have is how would one really write the "index, match" formula in VBA?
I have looked at several examples and not really getting my head around the examples.


Dim rng As Range 'Store Number
Dim rng1 As Range 'Do Not Call LookUp
Dim rng2 As Range 'Do Not Call Insert

Set rng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
Set rng1 = Range("U2:U" & Range("U" & Rows.Count).End(xlUp).Row)
Set rng2 = Range("D2:D" & Range("D" & Rows.Count).End(xlDown).Row)

With rng2
..Formula = "=index(V:V,MATCH(A2,U:U,0))"
..Value = .Value

End With


End Sub


Thanks Folks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default End process at last row of data

Hi,

The reason this runs on the entire column is because the macro is looking at every cell down column D. Assuming column D has no data, this would place the last row at the bottom of the sheet. Just change the rng2 argument to this:

Set rng2 = Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row)

The rest of the macro seemed to work fine on my machine.

Ben
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default End process at last row of data

On Tuesday, October 23, 2012 3:13:44 PM UTC-4, Ben McClave wrote:
Hi,



The reason this runs on the entire column is because the macro is looking at every cell down column D. Assuming column D has no data, this would place the last row at the bottom of the sheet. Just change the rng2 argument to this:



Set rng2 = Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row)



The rest of the macro seemed to work fine on my machine.



Ben


GOT IT!!! I did some of this 8+ yrs ago, but no longer have the workbooks, do not do this often and therefore cannot remember even 1/4 of it. So, "Range("A"...." is the column to find the last "filled" row. A little different than I remembered.
In the past I always worked the code then reverted to formulas, as in this example. So, another question, if I wanted to write the index, match in strict VBA code? I am not getting the Application---Match---Offset.
Ben, I appreciate all of your help!!!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default End process at last row of data

If it's a performance improvement that you are after, then ActiveSheet.UsedRange.Rows.Count is quite handy to prevent a loop from running on to the end of the worksheet. I use Intersect( ActiveSheet.Selection, ActiveSheet.UsedRange ) a lot to limit the scope of my macros that process selected rows.

If you need the more strict check that there has to be something in Column A, then you already have that in Ben's answer.

Phil.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro or VBA process varible row data Surrealdogma Excel Programming 1 June 29th 07 11:50 PM
Macro Required - to process data Pele Excel Programming 6 October 18th 05 04:57 PM
Is it possible to use 'grid' as a value in vb to process XL data? Philip Excel Discussion (Misc queries) 0 June 23rd 05 01:49 PM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
How to count process running time ( process not finished) miao jie Excel Programming 2 January 12th 05 06:01 AM


All times are GMT +1. The time now is 02:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"