Solved

Excel VBA Append data from one cell to another

Posted on 2013-11-04
5
674 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where is user Lync data stored 4 56
Deleting Unselectable Lines in Word 2013 2 29
splitting text of cell to columns 14 24
Add a range in an Excel graph 5 27
This article will show you how to use shortcut menus in the Access run-time environment.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now