Code:
Dim curRow as Long
For curRow = 1 to 10
Range("A" & curRow) = "Wow I just wrote to A" & curRow & "!"
Next curRow
EDIT:
In general, Cells will be the fastest, then ever so slightly behind (negligible) Offset, then Range. But for what it's worth I can't remember the last time I used Offset, you can always replace it with Cells, but it can help conceptually write the code.
Cells(2, 1) = Cells(1, 1).Offset(1, 0)
Or better example:
Cells(currentRow + offsetRows, 1) = Cells(currentRow, 1).Offset(offsetRows, 0)
You can convert everything into Cells if need be.
See, I knew I was close!
Your code runs a LOT faster. I've managed to tinker with it a bit...I switched the loops, so it starts looking on sentences first, THEN on keywords (the thought being, once it hits on one keyword, we can move to the next sentence). So I added logic to do that (since there's no "continue" I just used hacky stuff, setting the curReadRow to something ridiculously large, and the colInc to finalCol. That way when I get a hit, it moves to the next sentence).
One thing I can't figure out is before, it copied the whole row, and now it's only copying the sentence itself. I tried to use the "EntireRow" method but it seems odd to paste the entire row in to a cell, given that the line of code in question is:
Code:
Sheets("Sheet3").Cells(curPrintRow, 1) = sentence 'If it does, print it to sheet 3
This is where I get confused. Since we're iterating on the column with the sentence specifically, not the row in general, I wonder if this breaks the whole paradigm, or if there's some way at getting the entire row from a cell (which I assume there is) and then pasting it when we have the information we have (which I assume would use curPrintRow).
Edit: See, now I feel like I'll have to loop across each cell, setting each sell in the destination row to the corresponding cell in the source (sentence) row. That seems like a pain. Or, I guess, have an auxiliary "counter" for the outside (sentence) loop that keeps track of the row number, and then use the entireRow thing? Or can you somehow get that information from the "sentence" variable? Both seem sort of hacky. It'd be nice to do something like: target.Row = sentence.entireRow.
/edit
Further edit
I think I got it, using a little google fu. Anyone have a problem with:
Code:
Set wsSource = Sheets("Sheet1") 'Edit "Sheet1" to your source sheet name
Set wsDestin = Sheets("Sheet3")
With wsDestin
lngDestinRow = .Cells(.Rows.count, "P").End(xlUp).Offset(1, 0).row
.Cells(lngDestinRow, "A").EntireRow = sentence.EntireRow.Value
End With
Now, I don't get what the .Rows.count, "P".End thing does, exactly. I guess that determines the row we're on? And then the second one says take that row and copy it to my destination?
Yeah, it works, but I kinda have no idea why.
/further edit