Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to capture cell value then use it for a relative range selec

Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need to
copy formulas down a certain number of rows across a large number of columns
Each tab is different in terms of how many rows need to be copied. And, the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the first
shot so I thought I would be better off if I had a macro automate the process.

Cell A1 contains a value which is equal to the last row number that the
copying needs to go down to. Row 5 is the first row containing the formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at the
RANGE line with a <Run-time error '1004'. Method 'Range' of object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window popped up
wtih nothing in it.

Any help will be greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default Macro to capture cell value then use it for a relative range selec

Try: range(cells(a,b),cells(d,e))
and with while- if structures increment de a, b, c, and d values.

"PZ Straube" wrote:

Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need to
copy formulas down a certain number of rows across a large number of columns
Each tab is different in terms of how many rows need to be copied. And, the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the first
shot so I thought I would be better off if I had a macro automate the process.

Cell A1 contains a value which is equal to the last row number that the
copying needs to go down to. Row 5 is the first row containing the formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at the
RANGE line with a <Run-time error '1004'. Method 'Range' of object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window popped up
wtih nothing in it.

Any help will be greatly appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to capture cell value then use it for a relative range selec

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need to
copy formulas down a certain number of rows across a large number of

columns
Each tab is different in terms of how many rows need to be copied. And,

the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the first
shot so I thought I would be better off if I had a macro automate the

process.

Cell A1 contains a value which is equal to the last row number that the
copying needs to go down to. Row 5 is the first row containing the

formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in

cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select

with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at the
RANGE line with a <Run-time error '1004'. Method 'Range' of

object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window popped up
wtih nothing in it.

Any help will be greatly appreciated.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to capture cell value then use it for a relative range s

Tom,
Thanks for your response.

Sorry to bother you but when I went to run this macro, it stopped on the
"Dim rw as Row" line with an error message: "Compile error: User-defined type
not defined". Not really understanding what to do, I tried changing "as Row"
to "as Integer" then "as String". In both cases, it went into the body of
the macro but at the line, "sh.Range(sStr).FillDown" an error message said,
"<Run-time error '1004'. Method 'Range' of object'_Woksheet' failed.
Side question: Is this macro going to loop through all the tabs of this
spreadsheet?
Thanks again for helping me.

"Tom Ogilvy" wrote:

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need to
copy formulas down a certain number of rows across a large number of

columns
Each tab is different in terms of how many rows need to be copied. And,

the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the first
shot so I thought I would be better off if I had a macro automate the

process.

Cell A1 contains a value which is equal to the last row number that the
copying needs to go down to. Row 5 is the first row containing the

formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in

cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select

with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at the
RANGE line with a <Run-time error '1004'. Method 'Range' of

object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window popped up
wtih nothing in it.

Any help will be greatly appreciated.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to capture cell value then use it for a relative range s

Thanks for your reply.
I will give it a shot.
thanks again.

"filo666" wrote:

Try: range(cells(a,b),cells(d,e))
and with while- if structures increment de a, b, c, and d values.

"PZ Straube" wrote:

Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need to
copy formulas down a certain number of rows across a large number of columns
Each tab is different in terms of how many rows need to be copied. And, the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the first
shot so I thought I would be better off if I had a macro automate the process.

Cell A1 contains a value which is equal to the last row number that the
copying needs to go down to. Row 5 is the first row containing the formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at the
RANGE line with a <Run-time error '1004'. Method 'Range' of object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window popped up
wtih nothing in it.

Any help will be greatly appreciated.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to capture cell value then use it for a relative range s

That was a typo.

Yes, it will loop through all the tabs.

Sub FillSheets()
Dim rw as Long
Dim sh as Worksheet
Dim sStr as String
Dim rng as Range
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A5:CZ" & rw
set rng = Nothing
on Error Resume Next
set rng = sh.Range(sStr)
On Error goto 0
if not rng is nothing then
rng.Filldown
End If
Next
End Sub

I have modified the code to check and see if the string in A1 is a valid
range (it should be a number between 5 and 65536) I also adjusted the value
for the Variable sStr so it starts in row 5 (another typo).

--
Regards,
Tom Ogilvy



"PZ Straube" wrote in message
...
Tom,
Thanks for your response.

Sorry to bother you but when I went to run this macro, it stopped on the
"Dim rw as Row" line with an error message: "Compile error: User-defined

type
not defined". Not really understanding what to do, I tried changing "as

Row"
to "as Integer" then "as String". In both cases, it went into the body of
the macro but at the line, "sh.Range(sStr).FillDown" an error message

said,
"<Run-time error '1004'. Method 'Range' of object'_Woksheet' failed.
Side question: Is this macro going to loop through all the tabs of this
spreadsheet?
Thanks again for helping me.

"Tom Ogilvy" wrote:

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need

to
copy formulas down a certain number of rows across a large number of

columns
Each tab is different in terms of how many rows need to be copied.

And,
the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the

first
shot so I thought I would be better off if I had a macro automate the

process.

Cell A1 contains a value which is equal to the last row number that

the
copying needs to go down to. Row 5 is the first row containing the

formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in

cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select

with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at

the
RANGE line with a <Run-time error '1004'. Method 'Range' of

object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window

popped up
wtih nothing in it.

Any help will be greatly appreciated.






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to capture cell value then use it for a relative range s

Tom,

Thanks for all your time in responding to my query.

Unfortunately, using a temporary MsgBox just before the NEXT line, I found
that "rw" never changes from zero. That means that the Range/Rng is in error
which further means that it uses the "Then" part of the "If Not rng Is
Nothing..." line and skips over the FillDown line.

Sorry to ask but any suggestions for me?

As a side question regarding looping through all the tabs, since I have two
supporting tabs for notes in this spreadsheet that should not be affected by
this macro, is there a way to stop this macro before it loops around and
destroyed those two notes tabs?

Thanks!

"Tom Ogilvy" wrote:

That was a typo.

Yes, it will loop through all the tabs.

Sub FillSheets()
Dim rw as Long
Dim sh as Worksheet
Dim sStr as String
Dim rng as Range
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A5:CZ" & rw
set rng = Nothing
on Error Resume Next
set rng = sh.Range(sStr)
On Error goto 0
if not rng is nothing then
rng.Filldown
End If
Next
End Sub

I have modified the code to check and see if the string in A1 is a valid
range (it should be a number between 5 and 65536) I also adjusted the value
for the Variable sStr so it starts in row 5 (another typo).

--
Regards,
Tom Ogilvy



"PZ Straube" wrote in message
...
Tom,
Thanks for your response.

Sorry to bother you but when I went to run this macro, it stopped on the
"Dim rw as Row" line with an error message: "Compile error: User-defined

type
not defined". Not really understanding what to do, I tried changing "as

Row"
to "as Integer" then "as String". In both cases, it went into the body of
the macro but at the line, "sh.Range(sStr).FillDown" an error message

said,
"<Run-time error '1004'. Method 'Range' of object'_Woksheet' failed.
Side question: Is this macro going to loop through all the tabs of this
spreadsheet?
Thanks again for helping me.

"Tom Ogilvy" wrote:

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I need

to
copy formulas down a certain number of rows across a large number of
columns
Each tab is different in terms of how many rows need to be copied.

And,
the
number of rows for each tab changes periodically. I currently do this
manually but I sometimes don't get everything copied properly on the

first
shot so I thought I would be better off if I had a macro automate the
process.

Cell A1 contains a value which is equal to the last row number that

the
copying needs to go down to. Row 5 is the first row containing the
formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as specified in
cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of <Range("A5:CZ158").Select
with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped at

the
RANGE line with a <Run-time error '1004'. Method 'Range' of
object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window

popped up
wtih nothing in it.

Any help will be greatly appreciated.






  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to capture cell value then use it for a relative range s

rw = Sh.Range("A1").Value

Your the one that said the number of rows was in A1 of the sheet being
processed. That is where the code looks for the number of rows. If it
isn't there, not much I can say.

to skip sheets add an if statement in the loop.

for each sh in ThisWorkbook.Worksheets
if ucase(sh.name) < "ABC" and ucase(sh.Name) < "EFG" then





end if
Next

--
Regards,
Tom Ogilvy






"PZ Straube" wrote in message
...
Tom,

Thanks for all your time in responding to my query.

Unfortunately, using a temporary MsgBox just before the NEXT line, I found
that "rw" never changes from zero. That means that the Range/Rng is in

error
which further means that it uses the "Then" part of the "If Not rng Is
Nothing..." line and skips over the FillDown line.

Sorry to ask but any suggestions for me?

As a side question regarding looping through all the tabs, since I have

two
supporting tabs for notes in this spreadsheet that should not be affected

by
this macro, is there a way to stop this macro before it loops around and
destroyed those two notes tabs?

Thanks!

"Tom Ogilvy" wrote:

That was a typo.

Yes, it will loop through all the tabs.

Sub FillSheets()
Dim rw as Long
Dim sh as Worksheet
Dim sStr as String
Dim rng as Range
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A5:CZ" & rw
set rng = Nothing
on Error Resume Next
set rng = sh.Range(sStr)
On Error goto 0
if not rng is nothing then
rng.Filldown
End If
Next
End Sub

I have modified the code to check and see if the string in A1 is a

valid
range (it should be a number between 5 and 65536) I also adjusted the

value
for the Variable sStr so it starts in row 5 (another typo).

--
Regards,
Tom Ogilvy



"PZ Straube" wrote in message
...
Tom,
Thanks for your response.

Sorry to bother you but when I went to run this macro, it stopped on

the
"Dim rw as Row" line with an error message: "Compile error:

User-defined
type
not defined". Not really understanding what to do, I tried changing

"as
Row"
to "as Integer" then "as String". In both cases, it went into the

body of
the macro but at the line, "sh.Range(sStr).FillDown" an error message

said,
"<Run-time error '1004'. Method 'Range' of object'_Woksheet' failed.
Side question: Is this macro going to loop through all the tabs of

this
spreadsheet?
Thanks again for helping me.

"Tom Ogilvy" wrote:

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I

need
to
copy formulas down a certain number of rows across a large number

of
columns
Each tab is different in terms of how many rows need to be copied.

And,
the
number of rows for each tab changes periodically. I currently do

this
manually but I sometimes don't get everything copied properly on

the
first
shot so I thought I would be better off if I had a macro automate

the
process.

Cell A1 contains a value which is equal to the last row number

that
the
copying needs to go down to. Row 5 is the first row containing

the
formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the

row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as

specified in
cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of

<Range("A5:CZ158").Select
with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped

at
the
RANGE line with a <Run-time error '1004'. Method 'Range' of
object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window

popped up
wtih nothing in it.

Any help will be greatly appreciated.








  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Macro to capture cell value then use it for a relative range s

Tom,
First of all, thank you for taking your time to help me. I appreciate it
very much.
Not to be argumentative, but I'm confused with where you feel I said
anything other than A1 contained the final row number I needed to use. In my
last post, I simply stated that the macro was not picking up any value at all
for "rw" - something I determined from using a MsgBox.

Regardless, I played around with it and when I changed
rw = sh.Range("A1").Value and Set rng = sh.Range(sStr)
to
rw = Range("A1").Value and Set rng = Range(sStr)
it worked just fine. I don't know why taking the "sh." made it work but it
did (minus the moving from tab to tab). So my final version of the macro
looks like:

Sub FillSheets()

Dim rw As Long
Dim sh As Worksheet
Dim sStr As String
Dim rng As Range
For Each sh In ThisWorkbook.Worksheets
rw = Range("A1").Value
sStr = "A5:CZ" & rw
Set rng = Nothing
On Error Resume Next
Set rng = Range(sStr)
On Error GoTo 0
If Not rng Is Nothing Then
rng.FillDown
End If
Next

End Sub


Thanks again for your help. I learned a lot.



"Tom Ogilvy" wrote:

rw = Sh.Range("A1").Value

Your the one that said the number of rows was in A1 of the sheet being
processed. That is where the code looks for the number of rows. If it
isn't there, not much I can say.

to skip sheets add an if statement in the loop.

for each sh in ThisWorkbook.Worksheets
if ucase(sh.name) < "ABC" and ucase(sh.Name) < "EFG" then





end if
Next

--
Regards,
Tom Ogilvy






"PZ Straube" wrote in message
...
Tom,

Thanks for all your time in responding to my query.

Unfortunately, using a temporary MsgBox just before the NEXT line, I found
that "rw" never changes from zero. That means that the Range/Rng is in

error
which further means that it uses the "Then" part of the "If Not rng Is
Nothing..." line and skips over the FillDown line.

Sorry to ask but any suggestions for me?

As a side question regarding looping through all the tabs, since I have

two
supporting tabs for notes in this spreadsheet that should not be affected

by
this macro, is there a way to stop this macro before it loops around and
destroyed those two notes tabs?

Thanks!

"Tom Ogilvy" wrote:

That was a typo.

Yes, it will loop through all the tabs.

Sub FillSheets()
Dim rw as Long
Dim sh as Worksheet
Dim sStr as String
Dim rng as Range
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A5:CZ" & rw
set rng = Nothing
on Error Resume Next
set rng = sh.Range(sStr)
On Error goto 0
if not rng is nothing then
rng.Filldown
End If
Next
End Sub

I have modified the code to check and see if the string in A1 is a

valid
range (it should be a number between 5 and 65536) I also adjusted the

value
for the Variable sStr so it starts in row 5 (another typo).

--
Regards,
Tom Ogilvy



"PZ Straube" wrote in message
...
Tom,
Thanks for your response.

Sorry to bother you but when I went to run this macro, it stopped on

the
"Dim rw as Row" line with an error message: "Compile error:

User-defined
type
not defined". Not really understanding what to do, I tried changing

"as
Row"
to "as Integer" then "as String". In both cases, it went into the

body of
the macro but at the line, "sh.Range(sStr).FillDown" an error message
said,
"<Run-time error '1004'. Method 'Range' of object'_Woksheet' failed.
Side question: Is this macro going to loop through all the tabs of

this
spreadsheet?
Thanks again for helping me.

"Tom Ogilvy" wrote:

Dim rw as Row
Dim sh as Worksheet
Dim sStr as String
for each sh in ThisWorkbook.Worksheets
rw = Sh.Range("A1").Value
sStr = "A" & rw & ":CZ" & rw
sh.Range(sStr).Filldown
Next

--
Regards,
Tom Ogilvy


"PZ Straube" wrote in message
...
Hello,

I have an Excel 2003 spreadshet with 50+ tabs where in each tab I

need
to
copy formulas down a certain number of rows across a large number

of
columns
Each tab is different in terms of how many rows need to be copied.
And,
the
number of rows for each tab changes periodically. I currently do

this
manually but I sometimes don't get everything copied properly on

the
first
shot so I thought I would be better off if I had a macro automate

the
process.

Cell A1 contains a value which is equal to the last row number

that
the
copying needs to go down to. Row 5 is the first row containing

the
formulas
that need to be copied. Thus, for columns A:CZ from row 5 to the

row
specified in cell A1, I need to "copy down" those formulas

A static address/range macro with the last row of 158 (as

specified in
cell
A1) would look like:
*********************
Range("A5").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("A5:CZ158").Select
Selection.FillDown
*********************
I think I need to replace the "158" part of

<Range("A5:CZ158").Select
with
something dynamic, that changes with the value in cell A1.

I tried:
*********************
Dim Number_of_Rows As Integer
Number_of_Rows = Range("A1").Value

Last_Cell_for_FillDown = "CZ" & A1
Range_For_FillDown = "A5:" & Last_Cell_for_FillDown

Range(Range_For_FillDown).Select
Selection.FillDown
*********************
Frankly, I don't know if I need the DIM or not. The macro stopped

at
the
RANGE line with a <Run-time error '1004'. Method 'Range' of
object'_Global'
failed. When I hit the HELP button, a Visual Basic Help window
popped up
wtih nothing in it.

Any help will be greatly appreciated.









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
Macro relative cell reference decimal Excel Worksheet Functions 3 May 21st 09 11:36 PM
refer to cell relative to range Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 9 October 26th 07 03:03 PM
relative column referance to capture the 6 week average Janis Excel Discussion (Misc queries) 4 August 3rd 07 03:54 PM
A recorded Macro to hide certain selected columns hides non selec. Mlmotter Excel Programming 2 December 31st 04 02:56 PM
To have an entire row highlighted to some color if any cell in that row is selec Nick Excel Programming 1 January 19th 04 03:09 PM


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