cat.aires
09-29-2008, 05:44 AM
Hi all
I have a very long worksheet that I need to edit, and to avoid a lot of clicking I decided to try some VBA coding. But, being a first time VBA user, this is getting a lot more complicated than I first thought it would. And as much as I think this is an interesting field to explore and learn, I?m running against a deadline here? So, if someone can give me a little help, I would really appreciate it ? and I promise I will come back and learn!
So, what I have is something like this
StationCode.....long1.....long2.....lat1.....lat2.....plong.....plat
Station 1 ..........x1.........x2..........y1......y2
Station 2 ..........x3.........x4..........y3......y4
And what I want to do is:
1. Insert 3 rows under each of the already existing rows
2. Copy the cells in the first 5 columns to the new rows
3. Fill the plong and plat columns with the values in the other long/lat columns, in this way:
StationCode.....long1.....long2.....lat1.....lat2.....plong.....plat
Station 1..........x1..........x2..........y1......y2.......x1.........y1
Station 1..........x1..........x2..........y1......y2.......x1.........y2
Station 1..........x1..........x2..........y1......y2.......x2.........y2
Station 1..........x1..........x2..........y1......y2.......x2.........y1
And then do the same for the rest of the table.
I managed to find a little piece of code that inserts the new rows and change it to the number of rows I want, but now I?m stuck there. Help anyone?
Here is the code I already have
Sub AddRowsBetween()
Dim lLoop As Long
For lLoop = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
Cells(lLoop, 1).Range("A2:A4").EntireRow.Insert
Next lLoop
End Sub
I have a very long worksheet that I need to edit, and to avoid a lot of clicking I decided to try some VBA coding. But, being a first time VBA user, this is getting a lot more complicated than I first thought it would. And as much as I think this is an interesting field to explore and learn, I?m running against a deadline here? So, if someone can give me a little help, I would really appreciate it ? and I promise I will come back and learn!
So, what I have is something like this
StationCode.....long1.....long2.....lat1.....lat2.....plong.....plat
Station 1 ..........x1.........x2..........y1......y2
Station 2 ..........x3.........x4..........y3......y4
And what I want to do is:
1. Insert 3 rows under each of the already existing rows
2. Copy the cells in the first 5 columns to the new rows
3. Fill the plong and plat columns with the values in the other long/lat columns, in this way:
StationCode.....long1.....long2.....lat1.....lat2.....plong.....plat
Station 1..........x1..........x2..........y1......y2.......x1.........y1
Station 1..........x1..........x2..........y1......y2.......x1.........y2
Station 1..........x1..........x2..........y1......y2.......x2.........y2
Station 1..........x1..........x2..........y1......y2.......x2.........y1
And then do the same for the rest of the table.
I managed to find a little piece of code that inserts the new rows and change it to the number of rows I want, but now I?m stuck there. Help anyone?
Here is the code I already have
Sub AddRowsBetween()
Dim lLoop As Long
For lLoop = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
Cells(lLoop, 1).Range("A2:A4").EntireRow.Insert
Next lLoop
End Sub