Macro to copy/paste item from list

roheba

New Member
Joined
Oct 22, 2010
Messages
12
I have a list of names in Range A20:A55. Starting from Cell A20, I want to invoke a macro to copy current cell on the list to location "C3" then return to list and move down 1row to next item on the list. Then calculate and stop. Will repeat the macro from each item on the list, then calc and stop.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Update. Seems like such a simple macro... but I just can't get it right. To clarify, I want to invoke macro from top of list, at Cell A20. Want to copy contents of Call A20 to Cell C3. Then return to Cell A20 and move down to Cell A21. Then stop the macro. Then invoke the macro again from A21, copy contents to C3, move down to Cell A22, stop. Etc, etc. Seems so simple. I'm pulling my hair. Mucho thanks in advance.
 
Upvote 0
I know of no macro which can be run to start and stop and start and stop and start and stop

Why do you thinks you need to do things like this?
 
Upvote 0
Ok. I guess I was unclear. I thought "invoke" meant "to begin." What I need is really as simple as I explained: Copy contents from here to there, go down one row from here, and end the macro. After that, a complex iterative calculation process automatically runs. Then, when I'm ready, I can run the macro again from its new position (down one row from here). Hope that helps... and sincere thanks.
 
Upvote 0
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
If you are going to work your way right through the list in one session of excel, then try this
Code:
Sub Copy_Values_v1()
  Static rCurr As Range
  
  If rCurr Is Nothing Then Set rCurr = Range("A19")
  Set rCurr = rCurr.Offset(1)
  If rCurr.Row < 56 Then
    rCurr.Copy Destination:=Range("C3")
  Else
    MsgBox "Finished"
  End If
End Sub

If you might work part way through the list one day then come back on another day and wan to continue from where you left off, then we would need to store some information somewhere - I've used cell Z1.

Code:
Sub Copy_Values_v2()
  Dim rStore As Range
  
  Set rStore = Range("Z1")
  rStore.Value = rStore.Value + 1
  If rStore.Value < 20 Then rStore.Value = 20
  If rStore.Value < 56 Then
    Range("A" & rStore.Value).Copy Destination:=Range("C3")
  Else
    MsgBox "Finished"
  End If
End Sub
 
Upvote 0
Peter,

Thanks for the solutions. Both work well and I am using the latter version.

Problem solved, but…

I’m really curious to see if I might learn some VBA coding by asking you to critique (and perhaps tweak) my own effort.

Sub MyTryMacro1()

Range("A20").Select
ActiveWorkbook.Names.Add Name:="Spot1", RefersToR1C1:="=Analysis!R20C1"
ActiveWorkbook.Names("Spot1").Comment = ""
Selection.Copy
Range("C3").Select
ActiveSheet.Paste
Application.Goto Reference:="Spot1"
ActiveWorkbook.Names("Spot1").Delete
Application.CutCopyMode = False
Range("A21").Select

End Sub

As you can see, I took a different approach. I want to be able to place the cursor on any cell in the list of names, then by running the macro, do the copying and go to the next lower cell. Clearly, it doesn’t work because of the various absolute cell references. Is there a way to make this approach work such that the cell references would be determined by whatever the current cell is when the macro is invoked? Furthermore, it seems rather clumsy to jump from cell to cell to put the information into Cell C3. I’d guess you can suggest a more elegant way to accomplish this.

Again, much thanks for your attention and assist.
 
Upvote 0
Is there a way to make this approach work such that the cell references would be determined by whatever the current cell is when the macro is invoked?
In general I don't much like working with selecting cells/ranges and in many codes, selecting slows the code considerably. However, try
Code:
Sub Test()
  If Intersect(ActiveCell, Range("A20:A55")) Is Nothing Then Range("A20").Select
  Range("C3").Value = ActiveCell.Value
  ActiveCell.Offset(1).Select
End Sub


BTW, when posting code, please use Code tags to preserve any indentation.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top