Hi all,
I am new to the site and am looking for some wisdom to create a macro.
Data is imported to sheet 1 via a macro. I am working on another macro that will organize the imported data and move it to sheets 2 and 3. The imported data is three columns. Column A has data that is a combination of letters and numbers. Columns B and C are only numerical. All three columns will always be the same number of rows, but depending on what data is imported, the number of rows can vary.
The macro should look through the cells in column A and identify if it contains a specific word (case insensitive). If it does, then the macro will copy the cell in column A and the corresponding cell in column B and paste it in sheet2. If it does not, the cell in column A and the corresponding cell in column C is copied and pasted into sheet3.
Example:
<TBODY>
</TBODY>
Setting the search word as cat (again, case insensitive), the macro should result with:
Sheet2:
<TBODY>
</TBODY>
Sheet3:
<TBODY>
</TBODY>
Additional Notes: This information will be updated daily with new data so when the macro sorts the imported data to sheets 2 and 3, it will begin where the previous data ended.
I have some code that, so far, successfully imports to only one of the sheets, but will overwrite if I try to execute it again. This code is the result of digging through various forums looking for questions similar to mine. I am using an array, but thought perhaps some sort of if...then...else statement might be more appropriate. Also, I have to add combinations of upper and lower case letters for "cat" in this code, but would rather have a line that would designate case insensitive.
Any help would be greatly appreciated!!
I am new to the site and am looking for some wisdom to create a macro.
Data is imported to sheet 1 via a macro. I am working on another macro that will organize the imported data and move it to sheets 2 and 3. The imported data is three columns. Column A has data that is a combination of letters and numbers. Columns B and C are only numerical. All three columns will always be the same number of rows, but depending on what data is imported, the number of rows can vary.
The macro should look through the cells in column A and identify if it contains a specific word (case insensitive). If it does, then the macro will copy the cell in column A and the corresponding cell in column B and paste it in sheet2. If it does not, the cell in column A and the corresponding cell in column C is copied and pasted into sheet3.
Example:
Name | value1 | value2 |
Animalcat1 | 1 | 6 |
animaldog1 | 2 | 7 |
animalCAT2 | 3 | 8 |
animalDog2 | 4 | 9 |
animalCat3 | 5 | 10 |
<TBODY>
</TBODY>
Setting the search word as cat (again, case insensitive), the macro should result with:
Sheet2:
Name | Value1 |
Animalcat1 | 1 |
animalCAT2 | 3 |
animalCat3 | 5 |
<TBODY>
</TBODY>
Sheet3:
Name | Value2 |
animaldog1 | 7 |
animalDog2 | 9 |
<TBODY>
</TBODY>
Additional Notes: This information will be updated daily with new data so when the macro sorts the imported data to sheets 2 and 3, it will begin where the previous data ended.
I have some code that, so far, successfully imports to only one of the sheets, but will overwrite if I try to execute it again. This code is the result of digging through various forums looking for questions similar to mine. I am using an array, but thought perhaps some sort of if...then...else statement might be more appropriate. Also, I have to add combinations of upper and lower case letters for "cat" in this code, but would rather have a line that would designate case insensitive.
Code:
Sub SORT()
Dim cell As Range
Dim rngDest As Range
Dim i As Long
Dim arrColsToCopy
arrColsToCopy = Array(1, 2)
Set rngDest = Worksheets("sheet2").Range("A3")
Application.ScreenUpdating = False
For Each cell In Worksheets("sheet1").Range("A6:A1000").Cells
If cell Like "*CAT*" Or _
cell Like "*cat*" Or _
cell Like "*Cat*" Then
For i = LBound(arrColsToCopy) To UBound(arrColsToCopy)
With cell.EntireRow
.Cells(arrColsToCopy(i)).Copy rngDest.Offset(0, i)
End With
Next i
Set rngDest = rngDest.Offset(1, 0) 'next destination row
End If
Next cell
Application.ScreenUpdating = True
End Sub
Any help would be greatly appreciated!!