Solved

Excel VBA Append data from one cell to another

Posted on 2013-11-04
5
682 Views
Last Modified: 2013-11-05
Please refer to the spreadsheet that is attached “GQ Spreadsheet.xlsx” when reading this problem statement.

Background...
The cells in row 3, the green  fill color is RGB(153,255,51)
The cells in row 4, the yellow fill color is RGB(255,255,0)
Note - In this screen shot the TEXT in the 1st green cell is
"GQ-005 - Approval Time"
            and the next green cell has
"GQ-008 - GMP Certificate"

Process…
In the area BETWEEN the cells that have the green RGB(153,255,51), in this case Columns D to W...
I want to copy the value in column "E" (Not Applicable) to column "A"
     Then copy the value in column "O" (3 Months)       to column "A"  (appended)

•      Note that the column data that gets appended has the word "Regulatory" in the header with the yellow fill color.
•      Note that there is a third occurrence of "Regulatory", the data in that column contains "3 Months" which has already been appended, there should be no duplicate data that gets appended.

Hopefully this is clear. If not please ask any questions you may have.
Thanks for your help in advance.
GQ-Spreadsheet.xlsx
0
Comment
Question by:tesla764
  • 4
5 Comments
 

Author Comment

by:tesla764
ID: 39622103
This process should take place from the 1st column to the last.
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 500 total points
ID: 39623850
Please see if the following is what you want:

Sub UpdateData()
    Dim ColLast As Long, RowLast As Long
    Dim AppendStr As String, Str As String
    Dim RowIndex As Long, ColIndex As Long
    

    With Sheet1
        ColLast = .Cells(4, .Columns.Count).End(xlToLeft).Column
        RowLast = .Cells(.Rows.Count, "D").End(xlUp).Row
        Dim StrArray() As String, i As Integer
                
        For RowIndex = 5 To RowLast
            AppendStr = ""
            
            i = 0
            For ColIndex = 2 To ColLast
                If .Cells(4, ColIndex) = "Regulatory" And .Cells(3, ColIndex).Interior.ColorIndex <> 43 Then
                    Str = .Cells(RowIndex, ColIndex)
                    If i = 0 Then
                        AppendStr = Str
                        ReDim Preserve StrArray(i)
                        StrArray(UBound(StrArray)) = Str
                        i = i + 1
                    ElseIf UBound(Filter(StrArray, Str)) <= -1 Then
                        AppendStr = AppendStr & ", " & Str
                        ReDim Preserve StrArray(i)
                        StrArray(UBound(StrArray)) = Str
                        i = i + 1
                    End If
                End If
            Next ColIndex
            
            .Cells(RowIndex, 1) = AppendStr
        Next RowIndex
        
    End With

End Sub

Open in new window

0
 

Author Comment

by:tesla764
ID: 39624135
When the following statement is executed the error below occurs…

        ColLast = .Cells(4, .Columns.Count).End(xlToLeft).Column


Run-time error ‘424’;
Object required
0
 

Author Comment

by:tesla764
ID: 39624444
I changed this statement to use the current work sheet...

    With ActiveSheet.Name 'Sheet1
0
 

Author Closing Comment

by:tesla764
ID: 39624855
Thank You. This was very helpful.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question