Creating a Macro to Find Text and Then Merge Cells
Solved/Closed
katie215
Posts
4
Registration date
Monday May 19, 2014
Status
Member
Last seen
May 28, 2014
-
May 19, 2014 at 10:39 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 2, 2014 at 12:26 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 2, 2014 at 12:26 PM
Related:
- Creating a Macro to Find Text and Then Merge Cells
- Excel macro to create new sheet based on value in cells - Guide
- To create a network bridge you must ✓ - Network Forum
- Merge twitter accounts - Guide
- Cannot get my home pc to bridge connections - Windows Forum
- Can you merge instagram accounts ✓ - Instagram Forum
4 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
May 19, 2014 at 12:03 PM
May 19, 2014 at 12:03 PM
Hi Katie,
It clear to me what you want to do but unclear why.
1) A footer is always placed at the bottom of a document, which means a fixed position.
2) If the 3 cells to the right are empty, then the text in the first cell will be visible.
Anyway, the following code will go through column A looking for the 3 phrases and merging the next 3 cells to the right of the phrase found:
Best regards,
Trowa
It clear to me what you want to do but unclear why.
1) A footer is always placed at the bottom of a document, which means a fixed position.
2) If the 3 cells to the right are empty, then the text in the first cell will be visible.
Anyway, the following code will go through column A looking for the 3 phrases and merging the next 3 cells to the right of the phrase found:
Sub RunMe() Dim lRow As Integer lRow = Range("A" & Rows.Count).End(xlUp).Row For Each cell In Range("A1:A" & lRow) If cell = "Other grades include" _ Or cell = "Data reflect grades posted as of" _ Or cell = "Report produced by" Then Range(Cells(cell.Row, "A"), Cells(cell.Row, "D")).Merge End If Next cell End Sub
Best regards,
Trowa
katie215
Posts
4
Registration date
Monday May 19, 2014
Status
Member
Last seen
May 28, 2014
May 19, 2014 at 12:13 PM
May 19, 2014 at 12:13 PM
Hi Trowa- that worked! Thank you!
In regards to your 2 comments, I have hundreds of reports where these footers are at the bottom of the document, but the specific row changes as each report is a different length. And when the report is created (run from an automated program) the footer text doesn't span the columns, it just jams up into the cell in column A (the text wraps) so wanted to get it to spread out.
Thanks so much again for your help- I greatly appreciate it!
Katie
In regards to your 2 comments, I have hundreds of reports where these footers are at the bottom of the document, but the specific row changes as each report is a different length. And when the report is created (run from an automated program) the footer text doesn't span the columns, it just jams up into the cell in column A (the text wraps) so wanted to get it to spread out.
Thanks so much again for your help- I greatly appreciate it!
Katie
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
May 20, 2014 at 10:40 AM
May 20, 2014 at 10:40 AM
Thanks for the clarification Katie and I am glad to be able to help you.
See you
See you
katie215
Posts
4
Registration date
Monday May 19, 2014
Status
Member
Last seen
May 28, 2014
May 28, 2014 at 01:34 PM
May 28, 2014 at 01:34 PM
Hi-
I was wondering if you could help me modify this code slightly. Is there a way to say 'contains' instead of equals when the macro is looking for the text? The text of the 3 different cells changes ever so slightly every few months so if I could say if the cell contains "other grades include" then do the merge, it would save me from having to update the code every few months.
Thanks for your help!!
Katie
I was wondering if you could help me modify this code slightly. Is there a way to say 'contains' instead of equals when the macro is looking for the text? The text of the 3 different cells changes ever so slightly every few months so if I could say if the cell contains "other grades include" then do the merge, it would save me from having to update the code every few months.
Thanks for your help!!
Katie
katie215
Posts
4
Registration date
Monday May 19, 2014
Status
Member
Last seen
May 28, 2014
May 28, 2014 at 02:21 PM
May 28, 2014 at 02:21 PM
Okay nevermind- I posted this on another forum as well and got an answer (to change the equals to 'like' and add wildcards * in my text)
This is such a huge help though- thanks so much for helping me through this!
Katie
This is such a huge help though- thanks so much for helping me through this!
Katie
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 2, 2014 at 12:26 PM
Jun 2, 2014 at 12:26 PM
Thanks Katie for coming back to post your answer.