Consecutive cell copy

Corall

New Member
Joined
Sep 30, 2019
Messages
21
Howdy,

In column A there are several items. They can also be empty cells. Range is dynamic. There can be only 5 rows or 10 or 20 or ... In the cell there can be either numbers or letter / letters.
I would like for the first push of a button to copy the first cell from column A (say A2) to cell C1 and then run macro1.
at the next press, copy the next cell (A3) and put it in C1 (now in C1 it will be A2 & A3 - not the formula but the contents of cell A2 and A3 will be concatenated, then run macro2. And so on.
If in column A he finds an empty cell, ignore it, and in cell C1 there will be no empty space.

Let's say that in A2 = ah, A3 = 5, A4 = blank, A5 = zzz, C1 will be empty. At the first push of the button in C1 will be written "ah" (without the quotation marks), and will call macro 1, at the next push of the button the cell C1 will be ah5 then run macro 2, then again ah5, because A4 is empty, then ah5zzz and so ...

Thank you in advance.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
There can be only 5 rows or 10 or 20 or ...
Sounds like the could be 30 or more rows. Does that mean, should those rows be all filled, you really have 30 or 40 or more different macros to run after each concatenation?
 
Upvote 0
No. I have 8 macros. Usually column A has between 5 and 10 items and sometime could be 20 or 25. Then if necessary we put another small macro.
I think I can rem line with call macro x if no need macro.
 
Upvote 0
So if you have 8 macros and there are say 25 values, what exactly is supposed to happen after the 9th, 10th, 11th, .... , 25th concatenation?

Are the 8 macros at all similar? Could we see say the first 3 of them?
 
Upvote 0
We reuse some macro and if is necessary make another macro for new task.
We think macro will look like:

some line of code then
call macro1
some line of code then
call macro1
....
and if we have - say 15 rows and we need to run just 5 macros then we rem line with call macro xx

I can't post none of macro because they will be created according to future requirements.
Thank you to try to help me.
 
Upvote 0
some line of code then
call macro1
some line of code then
call macro1
Has the requirement now changed. This is running the same macro after the first two codes. I'm assuming that is a typo.

I am also assuming
- that the values in column A are constants. That is, they are not the result of formulas.
- that there will always be at least one of these constants in column A below row 1

In that case you could try a structure like this

VBA Code:
Sub Test()
  Dim Rng As Range, c As Range
  Dim s As String
  Dim k As Long
  Dim bCallMacro As Boolean
  
  Set Rng = Range("A2", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants)
  If Not Rng Is Nothing Then
    For Each c In Rng
      k = k + 1
      If Range("C1").Text = s Then
        Range("C1").Value = Range("C1").Text & c.Text
        bCallMacro = True
        Exit For
      Else
        s = s & c.Text
      End If
    Next c
    If bCallMacro Then
      Select Case k
        Case 1: Call Macro1
        Case 2: Call Macro2
        Case 3: Call Macro3
        ')
        ') Add more Case staatements as you wish
        ')
      End Select
    End If
  End If
End Sub
 
Upvote 0
Yes. Yes. That is great.
Thank you so much. It works perfectly.

PS It was a typo with macro1, must be macro2 and so on.
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

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