Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel VBA Append data from one cell to another

Posted on 2013-11-04
5
Medium Priority
?
721 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

New style of hardware planning for Microsoft Exchange server.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

876 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