Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
gjcase
 
Posts: n/a
Default Macro help - copy a cell down


I'm trying to do something simple, but it's not working, any help would
be appreciated.

I want a macro which will enter a formula into each cell of a table
column, for the range from the top of the column thru to the bottom of
the existing table. I have tried recording a macro to do this. The
macro enters the formula into the first cell, then copies it and pastes
to the rest of the column. In order to address the potential that a
table may have only one entry, I jump to the bottom of the spreadsheet,
then back up to the bottom of the data, then select the range from there
through the top of the data, less the top cell (so that I don't copy
into the cell above the table when there's just one entry.) Issue is
that I can't get the macro to correctly select the range, it seems to
skip the "step-down" instruction to avoid the top cell when I record
the macro. See below:

Sub HosedUp()
'
' Macro16 Macro
' Macro recorded 2005-09-02 by G
'
Selection.Copy
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(0, -1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Offset(-7, 0).Range("A1:A8").Select
ActiveCell.Activate
ActiveSheet.Paste
End Sub

Not sure what I'm doing wrong, but any suggestions would be welcomed.

---Glenn


--
gjcase
------------------------------------------------------------------------
gjcase's Profile: http://www.excelforum.com/member.php...o&userid=26061
View this thread: http://www.excelforum.com/showthread...hreadid=401593

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

Can you pick out a column that will always have data in it for every row that's
used?

If you can, maybe something like this would help:

dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("c1:c" & lastrow).formula = "yourformulahere"
end with

I used column A to get the last row of the table. I use column C to hold the
formula.


gjcase wrote:

I'm trying to do something simple, but it's not working, any help would
be appreciated.

I want a macro which will enter a formula into each cell of a table
column, for the range from the top of the column thru to the bottom of
the existing table. I have tried recording a macro to do this. The
macro enters the formula into the first cell, then copies it and pastes
to the rest of the column. In order to address the potential that a
table may have only one entry, I jump to the bottom of the spreadsheet,
then back up to the bottom of the data, then select the range from there
through the top of the data, less the top cell (so that I don't copy
into the cell above the table when there's just one entry.) Issue is
that I can't get the macro to correctly select the range, it seems to
skip the "step-down" instruction to avoid the top cell when I record
the macro. See below:

Sub HosedUp()
'
' Macro16 Macro
' Macro recorded 2005-09-02 by G
'
Selection.Copy
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(0, -1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Offset(-7, 0).Range("A1:A8").Select
ActiveCell.Activate
ActiveSheet.Paste
End Sub

Not sure what I'm doing wrong, but any suggestions would be welcomed.

---Glenn

--
gjcase
------------------------------------------------------------------------
gjcase's Profile: http://www.excelforum.com/member.php...o&userid=26061
View this thread: http://www.excelforum.com/showthread...hreadid=401593


--

Dave Peterson
  #3   Report Post  
gjcase
 
Posts: n/a
Default


Dave:

Thanks, that does just what I'm after, except I wanted to start at row
2 vs row 1. Changing the range statement fixed that. I appreciate the
help.

BTW, can you recommend a good book for learning excel macro
programming? Right now, I'm just bumbling around tweaking things I've
recorded, buit I'd like to get into it more.

---Glenn


--
gjcase
------------------------------------------------------------------------
gjcase's Profile: http://www.excelforum.com/member.php...o&userid=26061
View this thread: http://www.excelforum.com/showthread...hreadid=401593

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Debra Dalgleish has a list at her site:
http://www.contextures.com/xlbooks.html

John Walkenbach's is a nice one to start with. See if you can find them in your
local bookstore and you can choose what one you like best.

gjcase wrote:

Dave:

Thanks, that does just what I'm after, except I wanted to start at row
2 vs row 1. Changing the range statement fixed that. I appreciate the
help.

BTW, can you recommend a good book for learning excel macro
programming? Right now, I'm just bumbling around tweaking things I've
recorded, buit I'd like to get into it more.

---Glenn

--
gjcase
------------------------------------------------------------------------
gjcase's Profile: http://www.excelforum.com/member.php...o&userid=26061
View this thread: http://www.excelforum.com/showthread...hreadid=401593


--

Dave Peterson
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
Copy Paste Special Macro Bud Hughes Excel Discussion (Misc queries) 2 August 31st 05 02:00 AM
in cell editing macro ynissel Excel Discussion (Misc queries) 2 July 27th 05 07:28 PM
How can I copy cell formats in functions? Twitty Kitty Excel Worksheet Functions 3 July 24th 05 12:26 AM
macro help thephoenix12 Excel Discussion (Misc queries) 4 July 15th 05 05:57 PM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM


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