I just learned how to add in Excel a couple months ago and, although I'm doing the best I can with google, VBA is not easy for me to work with yet. So, while I certainly appreciate any sort of help, explanation-heavy answers would be doubly appreciated!
The excel file I've attached should explain it far more clearly than I can in words, but I'll try to summarize. I need to take a selection of cells and insert them into a table wherever text from a range show up.
Now, I should be - and have been - able to select the cells I want to insert and use the find method to find where to put them. Basically, find all instances of "packageA" and insert; I have a macro for this in the example worksheet. The problem is, I have a lot of different things to find. It needs to also insert on all the packageB's and C's and so on for a good 50 more, AND more are being added continuously. So, I can't just duplicate the macro for packageB and be done with it.
Here's what I'm using to find and insert:
Simply, instead of using find method to find one thing, I need to find anything that is in a range.
I imagine I can figure out this next part on my own eventually, but, after it's done doing that it needs to go back through and clear out blank rows. Some of the inserts leave one or several blank rows at the top, depending on which type of package they have been inserted on top of.
Seems like it should be so simple but I've spent ages without figuring it out...guess I need more grounding in VBA first.
Crossposted with example file here: http://www.ozgrid.com/forum/showthread.php?t=164129
The excel file I've attached should explain it far more clearly than I can in words, but I'll try to summarize. I need to take a selection of cells and insert them into a table wherever text from a range show up.
Now, I should be - and have been - able to select the cells I want to insert and use the find method to find where to put them. Basically, find all instances of "packageA" and insert; I have a macro for this in the example worksheet. The problem is, I have a lot of different things to find. It needs to also insert on all the packageB's and C's and so on for a good 50 more, AND more are being added continuously. So, I can't just duplicate the macro for packageB and be done with it.
Here's what I'm using to find and insert:
Code:
Sub FindandInsert()
Dim rFoundCell As Range
Dim LastCell As Range
Dim FirstAddr As String
Sheets("Sheet3").Select
With Range("B1:B1195")
Set LastCell = .Cells(.Cells.Count)
End With
Set rFoundCell = Range("B1:B1195").Find(What:="PackageA", After:=LastCell)
If Not rFoundCell Is Nothing Then
FirstAddr = rFoundCell.Address
End If
Do Until rFoundCell Is Nothing
Debug.Print rFoundCell.Address
Set rFoundCell = Range("B1:B1195").FindNext(After:=rFoundCell)
Range("InsertRange").Copy
rFoundCell.Select
Selection.Offset(0, -1).Insert Shift:=xlDown
If rFoundCell.Offset(-4, 0).Address = FirstAddr Then
Exit Do
End If
Loop
End Sub
Simply, instead of using find method to find one thing, I need to find anything that is in a range.
I imagine I can figure out this next part on my own eventually, but, after it's done doing that it needs to go back through and clear out blank rows. Some of the inserts leave one or several blank rows at the top, depending on which type of package they have been inserted on top of.
Seems like it should be so simple but I've spent ages without figuring it out...guess I need more grounding in VBA first.
Crossposted with example file here: http://www.ozgrid.com/forum/showthread.php?t=164129