Append macro

SandsB

Well-known Member
Joined
Feb 13, 2007
Messages
705
Office Version
  1. 365
Platform
  1. Windows
Cell B1 has text like this:
3/1/23: Pending patient results blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah,
blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah,
blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah,
3/2/23: Results negative
3/4/23: Final results blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah, blah,
blah, blah, blah, blah, blah, blah, blah, blah, blah

Cell A1 has similar text:
3/6/23: Completed

The text for each date may be a few characters or some small paragraphs.

I need a macro that'll move the text in A1 to the bottom (or top) of B1 retaining the separate lines by date (They were originally put there with an Alt-Enter) - and then clear the contents of A1. When I do this, with a simple concatenate in my macro, it removes the line breaks so all the text runs together and is no longer separated by date.

This is just for row 1. To make it more interesting, I need to assign the macro to a button on each row (I know how to do that) and take the above action for the row the button is on (I don't know that part) so one small macro works and I don't have to copy it 500 times for 500 rows of data. I don't see a way to let the macro know which line the button is on.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You want to do it one row at a time so that's why the button idea? You would need 500 buttons and all the difficulty that goes with that, not to mention unnecessary file bloat. You probably should be able to choose a suitable event instead. Perhaps right click on A1 to move contents to B1? You could get the row and/or column number for that and restrict canceling the event to right clicks on column A. Perhaps
VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If ActiveCell.Column = 1 Then
     Cancel = True
     ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, 1) & vbCrLf & ActiveCell
     ActiveCell = ""
End If

End Sub
 
Upvote 0
I see what you're saying and you're right. What I don't see is how to trigger this? "Occurs when a worksheet is right-clicked, before the default right-click action." ...but nothing happens
 
Upvote 0
Absolutely nothing happens? Not on any sheet when you right click? Then there must be an application setting I don't know about that ignores right click in the app, or at least the workbook. That would explain seeing absolutely nothing happen. I get a context menu when I right click anywhere except for column 1 on the sheet where I put the code.
 
Upvote 0
That makes sense - I found similar code online and none of those work either. I was wondering if there's some Office 365 setting turned off in my company. It would take a year to find out from tech support. Anybody have any ideas what I might check?
 
Upvote 0
Don't ask IT, ask Google. I did and got only code solutions to disable right clicks, so if you have no code in the workbook that does that, I'd say it's a non-starter. You also need to clarify if you want solutions. Me guessing what "nothing happens" means and you not clarifying isn't going to help anyone help you. The code I posted worked for me, but I guess I didn't declare that fact.
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,214
Members
449,091
Latest member
jeremy_bp001

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