Hi,
I'm trying to create some code to extract addresses from an Excel file so they can be imported into Access. We'll have to do this at least once a month on an Excel file formatted this way (and we have no control over the formatting). I don't have any experience with VBA for Excel, and I really only grope my way around in programming Access. I've cobbled some code together by extrapolating from the Help files that almost does what I want it to: go down through the cells in column D and copy and paste/transpose address information when the cell in D equals the cell in C (happens to have a name). There are a lot of extraneous rows, so I want it to delete the row if the cell in D is blank or doesn't equal the value in C. The problem I'm having is that once I delete the row, the active cell moves to the next row which means that when the code loops to the next cell, it ends up skipping a row (the "new" row after the old one is deleted). Can anyone help me figure out how to fix this "skipping" problem? Thanks a bunch!!! (Also, is there a way to determine how many rows it should do this activity to? 250 rows may not always be the right amount.)
Dim cell As Variant
Worksheets("Test").Activate
I'm trying to create some code to extract addresses from an Excel file so they can be imported into Access. We'll have to do this at least once a month on an Excel file formatted this way (and we have no control over the formatting). I don't have any experience with VBA for Excel, and I really only grope my way around in programming Access. I've cobbled some code together by extrapolating from the Help files that almost does what I want it to: go down through the cells in column D and copy and paste/transpose address information when the cell in D equals the cell in C (happens to have a name). There are a lot of extraneous rows, so I want it to delete the row if the cell in D is blank or doesn't equal the value in C. The problem I'm having is that once I delete the row, the active cell moves to the next row which means that when the code loops to the next cell, it ends up skipping a row (the "new" row after the old one is deleted). Can anyone help me figure out how to fix this "skipping" problem? Thanks a bunch!!! (Also, is there a way to determine how many rows it should do this activity to? 250 rows may not always be the right amount.)
Dim cell As Variant
Worksheets("Test").Activate
For Each cell In [d1:d250]
End Subcell.Activate
Select Case cell
Next cellSelect Case cell
Case IsNull(cell)
End SelectActiveCell.EntireRow.Delete
Case ActiveCell.Offset(0, -1)Range(ActiveCell, ActiveCell.Offset(3, 0)).Select
Selection.Copy
ActiveCell.Offset(3, 3).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=True
Case ElseSelection.Copy
ActiveCell.Offset(3, 3).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
True, Transpose:=True
If ActiveCell.Offset(0, 3) = "" Then ActiveCell.EntireRow.Delete