Creating a Macro to Find Text and Then Merge Cells
Solved/Closed
katie215
Posts
4
Registration date
Monday 19 May 2014
Status
Member
Last seen
28 May 2014
-
19 May 2014 à 10:39
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 2 Jun 2014 à 12:26
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 2 Jun 2014 à 12:26
Related:
- Creating a Macro to Find Text and Then Merge Cells
- Merge twitter accounts - Guide
- How to merge and compare two excel files - Guide
- To create a network bridge you must ✓ - Network Forum
- Based on the cell values in cells b77 ✓ - Excel Forum
- Creating a discord bot - Guide
4 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
19 May 2014 à 12:03
19 May 2014 à 12:03
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 19 May 2014
Status
Member
Last seen
28 May 2014
19 May 2014 à 12:13
19 May 2014 à 12:13
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 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
20 May 2014 à 10:40
20 May 2014 à 10:40
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 19 May 2014
Status
Member
Last seen
28 May 2014
28 May 2014 à 13:34
28 May 2014 à 13:34
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 19 May 2014
Status
Member
Last seen
28 May 2014
28 May 2014 à 14:21
28 May 2014 à 14:21
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 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
2 Jun 2014 à 12:26
2 Jun 2014 à 12:26
Thanks Katie for coming back to post your answer.