Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 846
Default Experimenting with (offset in VBA)


What I'm trying to change a heading on sheet 1 and print the page- the
"variable" heading information is in column A on sheet 3 and the first time
that is comes to a blank - end the loop. If print fine the first time and
then it gives me a Run-time error '13" on the Loop Until line

Am I even close with the logic found below?

Sub print_many()
Dim iRow As Long
iRow = 0
With Range("NameList")
Do
Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Experimenting with (offset in VBA)

There is an inherant paradox in using named ranges in code. A global named
range is visible from any sheet. When you write code however if you have a
line like

Range("NameList")
it is the same as
ActiveSheet.Range("NameList")

if NameList does not exist on the active sheet then the code will fail. So
as a guess your sheet 1 is active when you run this code. Since NameList is
on sheet 3 the code dies.

Take a look at this code to see if it makes sense to you...

Sub PrintMany()
Dim rng As Range
Dim rngToSearch As Range

With Sheet3
Set rngToSearch = .Range(.Range("NameList"), _
.Range("NameList").End(xlDown))
End With

For Each rng In rngToSearch
Sheet1.Range("TestName").Value = rng.Value
Sheet1.PrintPreview
Next rng
End Sub

or with your code...

Sub print_many()
Dim iRow As Long
iRow = 0
With Sheet3.Range("NameList")
Do
Sheet1.Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

End Sub
--
HTH...

Jim Thomlinson


"Brad" wrote:


What I'm trying to change a heading on sheet 1 and print the page- the
"variable" heading information is in column A on sheet 3 and the first time
that is comes to a blank - end the loop. If print fine the first time and
then it gives me a Run-time error '13" on the Loop Until line

Am I even close with the logic found below?

Sub print_many()
Dim iRow As Long
iRow = 0
With Range("NameList")
Do
Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Experimenting with (offset in VBA)

From the code posted I don't think NameList is a dynamic named range. I think
it is a single cell on sheet 3...
--
HTH...

Jim Thomlinson


"Don Guillett" wrote:

Can't quite tell what's going on here but, assuming your "rangelist" is
defined, why not just something like:

sub printem()
for each c in range("rangelist")
Range("TestName").Value = c
Sheet1.PrintOut
next c
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Brad" wrote in message
...

What I'm trying to change a heading on sheet 1 and print the page- the
"variable" heading information is in column A on sheet 3 and the first
time
that is comes to a blank - end the loop. If print fine the first time and
then it gives me a Run-time error '13" on the Loop Until line

Am I even close with the logic found below?

Sub print_many()
Dim iRow As Long
iRow = 0
With Range("NameList")
Do
Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 846
Default Experimenting with (offset in VBA)

I posted a thank you - but don't think that the message stuck.

It took a minute for me to understand rng as a rng and a counter, but the
lightbulb went off (at least I think that it did).

"Jim Thomlinson" wrote:

There is an inherant paradox in using named ranges in code. A global named
range is visible from any sheet. When you write code however if you have a
line like

Range("NameList")
it is the same as
ActiveSheet.Range("NameList")

if NameList does not exist on the active sheet then the code will fail. So
as a guess your sheet 1 is active when you run this code. Since NameList is
on sheet 3 the code dies.

Take a look at this code to see if it makes sense to you...

Sub PrintMany()
Dim rng As Range
Dim rngToSearch As Range

With Sheet3
Set rngToSearch = .Range(.Range("NameList"), _
.Range("NameList").End(xlDown))
End With

For Each rng In rngToSearch
Sheet1.Range("TestName").Value = rng.Value
Sheet1.PrintPreview
Next rng
End Sub

or with your code...

Sub print_many()
Dim iRow As Long
iRow = 0
With Sheet3.Range("NameList")
Do
Sheet1.Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

End Sub
--
HTH...

Jim Thomlinson


"Brad" wrote:


What I'm trying to change a heading on sheet 1 and print the page- the
"variable" heading information is in column A on sheet 3 and the first time
that is comes to a blank - end the loop. If print fine the first time and
then it gives me a Run-time error '13" on the Loop Until line

Am I even close with the logic found below?

Sub print_many()
Dim iRow As Long
iRow = 0
With Range("NameList")
Do
Range("TestName").Value = Sheet3.Range("a" & iRow + 1).Value
Sheet1.PrintOut
iRow = iRow + 1
Loop Until .Offset(iRow, 0).Value = ""
End With

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
Compare Cell Values, Offset(-1,0), Offset(-1,-1), and xlFillDefaul RyGuy Excel Worksheet Functions 2 September 28th 07 10:54 PM
Using Offset in VBA Matthew[_2_] Excel Discussion (Misc queries) 1 September 9th 07 05:12 PM
OFFSET Roger H[_2_] Excel Worksheet Functions 2 July 16th 07 01:37 PM
offset Eva Excel Worksheet Functions 2 January 29th 07 08:45 PM
VBA help with Offset gjcase Excel Discussion (Misc queries) 3 July 13th 06 02:35 PM


All times are GMT +1. The time now is 07:14 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"