ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Code Efficiency Question (https://www.excelbanter.com/excel-programming/338540-vba-code-efficiency-question.html)

Johnny[_9_]

VBA Code Efficiency Question
 
Can this code be paired-down for more efficiency?

week = InputBox("Enter the NASCAR Week", NASCAR_Week)
ActiveWorkbook.Names.Add name:=Range("A2").Value & week,
RefersToR1C1:="=" & week & "!R2C2"
ActiveWorkbook.Names.Add name:=Range("D2").Value & week,
RefersToR1C1:="=" & week & "!R2C5"
ActiveWorkbook.Names.Add name:=Range("G2").Value & week,
RefersToR1C1:="=" & week & "!R2C8"
ActiveWorkbook.Names.Add name:=Range("J2").Value & week,
RefersToR1C1:="=" & week & "!R2C11"

Thanks for checking this out.
John


Tom Ogilvy

VBA Code Efficiency Question
 
For efficiency, probably not, but you can loop:

week = InputBox("Enter the NASCAR Week", NASCAR_Week)
for i = 0 to 9 step 3
ActiveWorkbook.Names.Add name:=Range("A2") _
.Offset(0,i).Value & week,RefersToR1C1:= _
"=" & week & "!R2C" & i + 2
Next


--
Regards,
Tom Ogilvy



"Johnny" wrote in message
oups.com...
Can this code be paired-down for more efficiency?

week = InputBox("Enter the NASCAR Week", NASCAR_Week)
ActiveWorkbook.Names.Add name:=Range("A2").Value & week,
RefersToR1C1:="=" & week & "!R2C2"
ActiveWorkbook.Names.Add name:=Range("D2").Value & week,
RefersToR1C1:="=" & week & "!R2C5"
ActiveWorkbook.Names.Add name:=Range("G2").Value & week,
RefersToR1C1:="=" & week & "!R2C8"
ActiveWorkbook.Names.Add name:=Range("J2").Value & week,
RefersToR1C1:="=" & week & "!R2C11"

Thanks for checking this out.
John




Bob Phillips[_6_]

VBA Code Efficiency Question
 
Or just make it easier to read

week = InputBox("Enter the NASCAR Week", NASCAR_Week)
With ActiveWorkbook.Names
.Add name:=Range("A2").Value & week, _
RefersToR1C1:="=" & week & "!R2C2"
.Add name:=Range("D2").Value & week, _
RefersToR1C1:="=" & week & "!R2C5"
.Add name:=Range("G2").Value & week, _
RefersToR1C1:="=" & week & "!R2C8"
.Add name:=Range("J2").Value & week, _
RefersToR1C1:="=" & week & "!R2C11"
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Johnny" wrote in message
oups.com...
Can this code be paired-down for more efficiency?

week = InputBox("Enter the NASCAR Week", NASCAR_Week)
ActiveWorkbook.Names.Add name:=Range("A2").Value & week,
RefersToR1C1:="=" & week & "!R2C2"
ActiveWorkbook.Names.Add name:=Range("D2").Value & week,
RefersToR1C1:="=" & week & "!R2C5"
ActiveWorkbook.Names.Add name:=Range("G2").Value & week,
RefersToR1C1:="=" & week & "!R2C8"
ActiveWorkbook.Names.Add name:=Range("J2").Value & week,
RefersToR1C1:="=" & week & "!R2C11"

Thanks for checking this out.
John





All times are GMT +1. The time now is 05:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com