Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Using a Variable in a Formula

Tom Olgivy provided this to find the Last row in a spreadsheet that has
data in it, for another user here on the Forums.

Can anyone tell me how I can use the value "rw' to replace N1000 in the
below Macro?

Sub FindAndUseLastRow()
Dim rw As Long
if not isempty(Range("A" & rows.count)) then
rw = rows.count
else
rw = Cells(Rows.Count, "A").End(xlUp).Row
End if

Range("L2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,1,""-"")"
Range("M2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,2,""-"")"
Range("N2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,3,""-"")"
Range("L2:N2").Select
Selection.AutoFill Destination:=Range("L2:N1000), Type:=xlFillDefault
Range("L2:N1000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Using a Variable in a Formula

Sub FindAndUseLastRow()
Dim rw As Long
if not isempty(Range("A" & rows.count)) then
rw = rows.count
else
rw = Cells(Rows.Count, "A").End(xlUp).Row
End if

Range("L2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,1,""-"")"
Range("M2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,2,""-"")"
Range("N2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,3,""-"")"
Range("L2:N2").Select
Selection.AutoFill Destination:=Range("L2:N" & rw), Type:=xlFillDefault
Range("L2:N" & rw).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

--
Regards,
Tom Ogilvy

"VexedFist" wrote:

Tom Olgivy provided this to find the Last row in a spreadsheet that has
data in it, for another user here on the Forums.

Can anyone tell me how I can use the value "rw' to replace N1000 in the
below Macro?

Sub FindAndUseLastRow()
Dim rw As Long
if not isempty(Range("A" & rows.count)) then
rw = rows.count
else
rw = Cells(Rows.Count, "A").End(xlUp).Row
End if

Range("L2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,1,""-"")"
Range("M2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,2,""-"")"
Range("N2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,3,""-"")"
Range("L2:N2").Select
Selection.AutoFill Destination:=Range("L2:N1000), Type:=xlFillDefault
Range("L2:N1000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default Using a Variable in a Formula

Range, takes a string so you could convert the rw Long data type to a string
and use that instead:

Sub FindAndUseLastRow()
Dim rw As Long
Dim sRange As String
If Not IsEmpty(Range("A" & Rows.Count)) Then
rw = Rows.Count
Else
rw = Cells(Rows.Count, "A").End(xlUp).Row
End If

Range("L2").FormulaR1C1 = "='MACRO HiPath 4000"
OptiDat.xls '!ExtractElement(RC16,1,""-"")"
Range("M2").FormulaR1C1 = "='MACRO HiPath 4000"
OptiDat.xls '!ExtractElement(RC16,2,""-"")"
Range("N2").FormulaR1C1 = "='MACRO HiPath 4000"
OptiDat.xls '!ExtractElement(RC16,3,""-"")"
Range("L2:N2").Select
sRange = "L2:N" & CStr(rw)
Selection.AutoFill Destination:=Range(sRange), _
Type:=xlFillDefault
Range(sRange).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub

Hope that helps

Best regards

John


"VexedFist" wrote in message
ups.com...
Tom Olgivy provided this to find the Last row in a spreadsheet that has
data in it, for another user here on the Forums.

Can anyone tell me how I can use the value "rw' to replace N1000 in the
below Macro?

Sub FindAndUseLastRow()
Dim rw As Long
if not isempty(Range("A" & rows.count)) then
rw = rows.count
else
rw = Cells(Rows.Count, "A").End(xlUp).Row
End if

Range("L2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,1,""-"")"
Range("M2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,2,""-"")"
Range("N2").FormulaR1C1 = "='MACRO HiPath 4000
OptiDat.xls'!ExtractElement(RC16,3,""-"")"
Range("L2:N2").Select
Selection.AutoFill Destination:=Range("L2:N1000), Type:=xlFillDefault
Range("L2:N1000").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub



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
Using a variable in a formula [email protected] Excel Discussion (Misc queries) 1 December 29th 06 11:46 AM
formula containing a formula-dependent variable - how? CompeterN New Users to Excel 1 November 8th 06 02:02 PM
Using a variable in a VBA formula Colin Vicary Excel Discussion (Misc queries) 3 November 8th 05 11:39 AM
Help With a Variable Formula jdurrmsu Excel Programming 1 September 16th 05 04:22 PM
Variable in a formula GM[_2_] Excel Programming 6 March 3rd 04 06:27 PM


All times are GMT +1. The time now is 01:09 PM.

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"