Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default How to Offset string variable?

This is my line of code :

Area = ActiveSheet.PageSetup.PrintArea 'Sets string variable Area to
"A1:D10"

I then do a loop. I want to look at each row of the "Area"

I need to know how I could update the String variable "Area" to "B1:D10",
then "C1:D10" and so on.

Thanks for any help, I'm stuck!

Alan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default How to Offset string variable?

Following are two different macros. The first returns the
current print area one row at a time as a string. The
second returns the print area decreased one row at a time
as a string. I wasn't sure which you really wanted.

Sub XXX()
Dim Area As String
Dim Rng1 As Range, Rng2 As Range
Dim i As Integer
Area = ActiveSheet.PageSetup.PrintArea
Set Rng1 = Range(Area)
For i = 1 To Rng1.Rows.Count
Set Rng2 = Intersect(Rng1.Rows(i), Rng1)
MsgBox Rng2.Address
Next
End Sub

Sub YYY()
Dim Area As String
Dim Rng1 As Range, Rng2 As Range
Dim i As Integer, NumRows As Integer
Dim strStartRow As String, strEndRow As String
Area = ActiveSheet.PageSetup.PrintArea
Set Rng1 = Range(Area)
NumRows = Rng1.Rows.Count
strEndRow = CStr(Rng1.Rows(NumRows).Row)
For i = 1 To NumRows
strStartRow = CStr(Rng1.Rows(i).Row)
Set Rng2 = Intersect(Rng1, Rows(strStartRow & ":" & _
strEndRow))
MsgBox Rng2.Address
Next
End Sub

Regards,
Greg

-----Original Message-----
This is my line of code :

Area = ActiveSheet.PageSetup.PrintArea 'Sets string

variable Area to
"A1:D10"

I then do a loop. I want to look at each row of the "Area"

I need to know how I could update the String

variable "Area" to "B1:D10",
then "C1:D10" and so on.

Thanks for any help, I'm stuck!

Alan


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 218
Default How to Offset string variable?

The second macro is clumsy. This is better:

Sub YYY()
Dim Area As String
Dim Rng1 As Range, Rng2 As Range
Dim StartRow As Range, EndRow As Range
Dim i As Integer, NumRows As Integer
Area = ActiveSheet.PageSetup.PrintArea
Set Rng1 = Range(Area)
NumRows = Rng1.Rows.Count
Set EndRow = Rng1.Rows(NumRows)
For i = 1 To NumRows
Set StartRow = Rng1.Rows(i)
Set Rng2 = Intersect(Rng1, Range(StartRow, EndRow))
MsgBox Rng2.Address
Next
End Sub

Regards,
Greg
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
VLookup Variable Offset Glenda Excel Discussion (Misc queries) 1 April 7th 10 02:01 PM
Sum variable range of column entries in offset cell Struggling in Sheffield[_2_] New Users to Excel 5 October 10th 09 05:16 PM
Variable worksheet name in offset Dave T Excel Worksheet Functions 2 January 25th 07 07:41 PM
Transpose? Offset? Variable starting cell Fin Analyst Excel Discussion (Misc queries) 4 April 26th 06 07:48 AM
Join string with variable name to get variable value Dianne Excel Programming 6 February 12th 04 04:24 AM


All times are GMT +1. The time now is 10:35 AM.

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"