Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Improvement to sub: Detect data extent and convert to values

Hi guys,

I'm trying to improve the sub below, so that:

a) it auto-detects the extent of the data range in col A
(A2:Ax, where x = last cell)
and inserts the vlookup formula correspondingly into col C

b) it will then auto-convert the returns in col C to values,
after calculation

Sub InsertFormulas()
With Sheets("Book In").Range("C2:C100")
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!R2C1:R1 000C2,2,FALSE))"
End With
End Sub

Thanks for insights
--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Improvement to sub: Detect data extent and convert to values

Hi
try

Sub InsertFormulas()
dim lastrow as long
With Sheets("Book In")
lastrow = .Cells(Rows.count, "A").End(xlUp).row
end with
with Sheets("Book In").Range("C2:C" & lastrow)
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!
R2C1:R1000C2,2,FALSE))"

'convert formulas to values
..value=.value
End With
End Sub







-----Original Message-----
Hi guys,

I'm trying to improve the sub below, so that:

a) it auto-detects the extent of the data range in col A
(A2:Ax, where x = last cell)
and inserts the vlookup formula correspondingly into col C

b) it will then auto-convert the returns in col C to

values,
after calculation

Sub InsertFormulas()
With Sheets("Book In").Range("C2:C100")
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!

R2C1:R1000C2,2,FALSE))"
End With
End Sub

Thanks for insights
--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Improvement to sub: Detect data extent and convert to values

Works great!

Many thanks, Frank

--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Improvement to sub: Detect data extent and convert to values

sorry to butt in ... but some tidy up....


Sub InsertFormulas()
dim lastrow as long
dim sFormula as string

sFormula="=IF(RC1="""","""",VLOOKUP(RC1, _
PartNumbers!R2C1:R1000C2,2,FALSE))"
With Sheets("Book In")
lastrow = .Cells(Rows.count, "A").End(xlUp).row
with .Range(.Range("C2"),.Cells(lastrow,"C"))
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = sFormula
'convert formulas to values
.value=.value
End With

END WITH
End Sub



:)




-----Original Message-----
Hi
try

Sub InsertFormulas()
dim lastrow as long
With Sheets("Book In")
lastrow = .Cells(Rows.count, "A").End(xlUp).row
end with
with Sheets("Book In").Range("C2:C" & lastrow)
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!
R2C1:R1000C2,2,FALSE))"

'convert formulas to values
..value=.value
End With
End Sub







-----Original Message-----
Hi guys,

I'm trying to improve the sub below, so that:

a) it auto-detects the extent of the data range in col A
(A2:Ax, where x = last cell)
and inserts the vlookup formula correspondingly into

col C

b) it will then auto-convert the returns in col C to

values,
after calculation

Sub InsertFormulas()
With Sheets("Book In").Range("C2:C100")
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!

R2C1:R1000C2,2,FALSE))"
End With
End Sub

Thanks for insights
--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Improvement to sub: Detect data extent and convert to values

Hi Patrick
no problem at all :-)

-----Original Message-----
sorry to butt in ... but some tidy up....


Sub InsertFormulas()
dim lastrow as long
dim sFormula as string

sFormula="=IF(RC1="""","""",VLOOKUP(RC1, _
PartNumbers!R2C1:R1000C2,2,FALSE))"
With Sheets("Book In")
lastrow = .Cells(Rows.count, "A").End(xlUp).row
with .Range(.Range("C2"),.Cells(lastrow,"C"))
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = sFormula
'convert formulas to values
.value=.value
End With

END WITH
End Sub



:)




-----Original Message-----
Hi
try

Sub InsertFormulas()
dim lastrow as long
With Sheets("Book In")
lastrow = .Cells(Rows.count, "A").End(xlUp).row
end with
with Sheets("Book In").Range("C2:C" & lastrow)
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!
R2C1:R1000C2,2,FALSE))"

'convert formulas to values
..value=.value
End With
End Sub







-----Original Message-----
Hi guys,

I'm trying to improve the sub below, so that:

a) it auto-detects the extent of the data range in col A
(A2:Ax, where x = last cell)
and inserts the vlookup formula correspondingly into

col C

b) it will then auto-convert the returns in col C to

values,
after calculation

Sub InsertFormulas()
With Sheets("Book In").Range("C2:C100")
' Adjust the range in col C to suit
' the max likely number of data rows in col A
.FormulaR1C1 = _
"=IF(RC1="""","""",VLOOKUP(RC1,PartNumbers!

R2C1:R1000C2,2,FALSE))"
End With
End Sub

Thanks for insights
--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


.

.

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Improvement to sub: Detect data extent and convert to values

Hey, that works great, too!

Thanks for the "tidy up", Patrick

I'm going to try and grasp the refinements made ..

--
Rgds
Max
xl 97
---
Please respond in thread
xdemechanik <atyahoo<dotcom
----


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
Excel 2007 SP1 - How to correct scrollbar extent? Ron West Excel Discussion (Misc queries) 1 January 2nd 09 03:31 PM
How do I make a formula automatically detect changes in values LMoore Excel Worksheet Functions 1 March 28th 07 04:44 PM
Convert Data Range in to individual values mistryrg Excel Discussion (Misc queries) 2 June 7th 06 04:48 PM
how do i detect like text and add corresponding values? Lucy Excel Discussion (Misc queries) 2 December 17th 04 04:59 PM
Defining Range Extent Nigel[_4_] Excel Programming 2 October 5th 03 12:10 PM


All times are GMT +1. The time now is 07:39 AM.

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

About Us

"It's about Microsoft Excel"