View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Martin Fishlock Martin Fishlock is offline
external usenet poster
 
Posts: 694
Default Macro for Editing Data

Hi Will :

Try this lttle macro:

Option Explicit

Sub insertblanks()
Dim lRow As Long
Dim lCol As Long
Dim lColPlus1 As Long
Dim lColPlus2 As Long

If (MsgBox("Is the cursor in on the left column " _
& "of the first row of data?", _
vbCritical + vbYesNo, "Starting...") = vbNo) Then
MsgBox "Try again....", vbOKOnly, "Stopping..."
Exit Sub
End If
With ActiveSheet
lRow = ActiveCell.Row
lCol = ActiveCell.Column
lColPlus1 = lCol + 1
lColPlus2 = lCol + 2
Do While .Cells(lRow, lCol) < ""
If .Cells(lRow, lCol) < _
.Cells(lRow, lColPlus1) Then
.Range(.Cells(lRow, lColPlus1), _
.Cells(lRow, lColPlus2)).Insert xlDown
End If
lRow = lRow + 1
Loop
End With
End Sub

Just put the cursor in the top left cell of the table.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


" wrote:

I have three columns of data - the first is a master list of
countries, the second an incomplete list that has a third column
referring to this. I want to somehow create a script to match up the
second and third columns with the first. For example:

Row 1: America - America - 3
Row 2: Belgium - Belgium - 5
Row 3: Belize - Canada - 10
Row 4: Canada - Cape Verde - 7
Row 5: Cape Verde, etc...


The numbers in the third column don't have any significance. Since
the first column is complete, I want to shift the second and third
columns down a row after "Belgium" so there is a blank after Belize,
and the next row lines up - (it says Canada in all rows). So it
should become:

Row 1: America - America - 3
Row 2: Belgium - Belgium - 5
Row 3: Belize - BLANK
Row 4: Canada - Canada - 10
Row 5: Cape Verde - Cape Verde - 7
etc....


I have LOTS of columns and rows of this data, and I need to match them
all up. Is there a good way to do this? Or do I just have to do it
by hand??

Thanks SO much for your help!

Will