Macro to copy paste single cell at the time from the list

Henceman

New Member
Joined
Oct 9, 2017
Messages
46
I have following simple code, which takes values from A column and pastes them to B2, one by one, and runs some code on each of these values, which is not relevant to this question.


VBA Code:
Range("A13").Copy Range("B2")
Range("A14").Copy Range("B2")
Range("A15").Copy Range("B2")
Range("A16").Copy Range("B2")
Range("A17").Copy Range("B2")
...

Problem is, that the amount of values I have in A column is not fixed, there might be 5, might be 15 or more. I cannot tell macro to simply copy and paste values from 13-to 17.

How can I set this range to be dynamic, so if there are only two values, macro stops after these two?
 
Blank space is in an indicator. Data starts always from A13, and continues down, until there is an empty cell in between,
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Will there always be data in A14?
 
Upvote 0
Ok, how about
VBA Code:
Sub Henceman()
   Dim Cl As Range
   Dim Lr As Long
   
   If [a14] = "" Then Lr = 13 Else Lr = [a13].End(xlDown).row
   For Each Cl In Range("A13:A" & Lr)
      Cl.Copy Range("B2")
      'your code here
   Next Cl
End Sub
 
Upvote 0
Thank you Fluff! I tried and tested, this is a solution im going for right now! Sorry for long delay getting back to you.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,589
Members
449,174
Latest member
chandan4057

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