Insert Column based on data in Row.
I was unable to find the answer to this question. I know it is out
there but for some reason my search results are not providing what I need lately. I have a spreadsheet that varies in the number of columns (A through Whatever). I want to use VBA to look at Row 2 and anywhere it says a word or phrase (let's say "happy summer") I want to be able to insert another column. For example if D2 says "happy summer" I want to insert a column on F and if, if B2 says "happy summer" I would want to insert a column on C. Any thoughts out there? You guys and gals are always very helpful. Thank you, Dow. |
Insert Column based on data in Row.
Is there any logic with which to determine where to insert a column if the
specified data is in some other column? Do you have a list of texts to look for or just one? HTH Otto "Dow" wrote in message ... I was unable to find the answer to this question. I know it is out there but for some reason my search results are not providing what I need lately. I have a spreadsheet that varies in the number of columns (A through Whatever). I want to use VBA to look at Row 2 and anywhere it says a word or phrase (let's say "happy summer") I want to be able to insert another column. For example if D2 says "happy summer" I want to insert a column on F and if, if B2 says "happy summer" I would want to insert a column on C. Any thoughts out there? You guys and gals are always very helpful. Thank you, Dow. |
Insert Column based on data in Row.
On Aug 3, 3:50*pm, "Otto Moehrbach"
wrote: Is there any logic with which to determine where to insert a column if the specified data is in some other column? *Do you have a list of texts to look for or just one? *HTH *Otto"Dow" wrote in message ... I was unable to find the answer to this question. *I know it is out there but for some reason my search results are not providing what I need lately. I have a spreadsheet that varies in the number of columns (A through Whatever). *I want to use VBA to look at Row 2 and anywhere it says a word or phrase (let's say "happy summer") I want to be able to insert another column. For example if D2 says "happy summer" I want to insert a column on F and if, if B2 says "happy summer" I would want to insert a column on C. Any thoughts out there? *You guys and gals are always very helpful. Thank you, Dow.- Hide quoted text - - Show quoted text - At this time it is just the one text "happy summer". If I choose to add more I think I know how to do that with named ranges based on a previous workbook I built. At this time the data will be in row 2 without exception. The columns can vary from 5 to 70+. The logic should be - If row 2 Column X (Columns will vary and there will be more than one of them with the required text) says "happy summer" insert column on the next position or Y in this case. |
Insert Column based on data in Row.
This little macro will look in all the entries in row 2, and if the entry is
"happy summer", it will insert a new blank column immediately to the right. HTH Otto Sub InsertColumns() Dim rRow2 As Range Dim c As Long Set rRow2 = Range("A2", Cells(2, Columns.Count).End(xlToLeft)) For c = rRow2.Count To 1 Step -1 If rRow2(c) = "happy summer" Then rRow2(c + 1).EntireColumn.Insert End If Next c End Sub "Dow" wrote in message ... On Aug 3, 3:50 pm, "Otto Moehrbach" wrote: Is there any logic with which to determine where to insert a column if the specified data is in some other column? Do you have a list of texts to look for or just one? HTH Otto"Dow" wrote in message ... I was unable to find the answer to this question. I know it is out there but for some reason my search results are not providing what I need lately. I have a spreadsheet that varies in the number of columns (A through Whatever). I want to use VBA to look at Row 2 and anywhere it says a word or phrase (let's say "happy summer") I want to be able to insert another column. For example if D2 says "happy summer" I want to insert a column on F and if, if B2 says "happy summer" I would want to insert a column on C. Any thoughts out there? You guys and gals are always very helpful. Thank you, Dow.- Hide quoted text - - Show quoted text - At this time it is just the one text "happy summer". If I choose to add more I think I know how to do that with named ranges based on a previous workbook I built. At this time the data will be in row 2 without exception. The columns can vary from 5 to 70+. The logic should be - If row 2 Column X (Columns will vary and there will be more than one of them with the required text) says "happy summer" insert column on the next position or Y in this case. |
All times are GMT +1. The time now is 01:33 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com