Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Macro Conversion To Relative Cells

I recorded a macro and got the following:

Range("A13").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A14").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Selection.ClearContents
Range("A14").Select

I want to make this a macro the user can run that does the following.
Whatever cell the user is on, it copies the row above to the row the user is
on. There are lists and data validations, so it copies all that over. But I
want all the values to be blank. Is there a better way to do this, using
relative paths (instead of A13), and not using copy and paste, and maybe a
way to do this without having to do ClearContents, so everything but the
text is copied. A newbie at Excel vba...



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macro Conversion To Relative Cells

Option Explicit
Sub testme()

Dim myCell As Range
Dim RngToCopy As Range

Set myCell = ActiveCell

If myCell.Row = 1 Then
MsgBox "Not on this row, buddy!"
Exit Sub
End If

'copy the entire row?
Set RngToCopy = myCell.Offset(-1, 0).EntireRow
myCell.EntireRow.Insert
RngToCopy.Copy _
Destination:=RngToCopy.Offset(1, 0).Cells(1)

'clean up constants
On Error Resume Next 'just in case there are no constants
RngToCopy.Offset(1, 0).Cells.SpecialCells(xlCellTypeConstants).ClearCo ntents
On Error GoTo 0

End Sub


Derek Hart wrote:

I recorded a macro and got the following:

Range("A13").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Range("A14").Select
Selection.Insert Shift:=xlDown
Application.CutCopyMode = False
Selection.ClearContents
Range("A14").Select

I want to make this a macro the user can run that does the following.
Whatever cell the user is on, it copies the row above to the row the user is
on. There are lists and data validations, so it copies all that over. But I
want all the values to be blank. Is there a better way to do this, using
relative paths (instead of A13), and not using copy and paste, and maybe a
way to do this without having to do ClearContents, so everything but the
text is copied. A newbie at Excel vba...


--

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
Macro Relative Cells Bazy2k Excel Discussion (Misc queries) 3 February 18th 10 04:24 PM
How to chnge 35 relative cells to 35 absolute cells at one time. Susan A at Millennium Medical Excel Worksheet Functions 3 March 7th 06 08:12 PM
Relative cells in macro - and pasting a formula too! Excel Discussion (Misc queries) 3 February 23rd 06 02:46 PM
Relative cells in macro - and pasting a formula too. No Name Excel Programming 1 February 23rd 06 01:20 PM
macro to copy absolute cells, then paste relative Bill Carr Excel Programming 1 November 16th 04 10:42 PM


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