Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy & paste cell after inserting blank row

I have an Excel sheet with two columns of data for which I would like to
format. I need to add two rows at each change in column A (the no. of rows
for the change to occur varies). Next I would like to copy the first cell in
column B where the change occurs in column A to one cell above column A
where the change occured (like a header). The following table describes what
I would like to do.

This is the data b4 processing.
A B
6 Data A 123
7 Data A 123
8 Data B 234
9 Data B 234

This is the format that I need after processing.
7 123
8 Data A 123
9 Data A 123
10
11 234
12 Data B 234
13 Data B 234

So far, I have managed to obtain the following code to add two rows at each
change of column A. I can't figure out how the copying and pasting is done
via code. Could someone help? Thanks.

Sub InsertTwoRowsAtChangesInColumn()
Dim i As Long
For i = ActiveSheet.UsedRange.Rows.Count To 6 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Cells(i, 1).EntireRow.Insert
Cells(i, 1).EntireRow.Insert
End If
Next i
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copy & paste cell after inserting blank row

Hi Dan,

Try:

Sub InsertTwoRowsAtChangesInColumn()
Dim i As Long
Dim CalcMode As Long

CalcMode = Application.Calculation

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

For i = ActiveSheet.UsedRange.Rows.Count To 6 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Cells(i, 1).Resize(2).EntireRow.Insert
Cells(i + 1, 1).Value = Cells(i + 2, 2).Value
End If
Next i

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

---
Regards,
Norman



"Dan" wrote in message
...
I have an Excel sheet with two columns of data for which I would like to
format. I need to add two rows at each change in column A (the no. of rows
for the change to occur varies). Next I would like to copy the first cell
in
column B where the change occurs in column A to one cell above column A
where the change occured (like a header). The following table describes
what
I would like to do.

This is the data b4 processing.
A B
6 Data A 123
7 Data A 123
8 Data B 234
9 Data B 234

This is the format that I need after processing.
7 123
8 Data A 123
9 Data A 123
10
11 234
12 Data B 234
13 Data B 234

So far, I have managed to obtain the following code to add two rows at
each
change of column A. I can't figure out how the copying and pasting is done
via code. Could someone help? Thanks.

Sub InsertTwoRowsAtChangesInColumn()
Dim i As Long
For i = ActiveSheet.UsedRange.Rows.Count To 6 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Cells(i, 1).EntireRow.Insert
Cells(i, 1).EntireRow.Insert
End If
Next i
End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy & paste cell after inserting blank row

Works great, Norman. Thanks.



"Norman Jones" wrote in message
...
Hi Dan,

Try:

Sub InsertTwoRowsAtChangesInColumn()
Dim i As Long
Dim CalcMode As Long

CalcMode = Application.Calculation

With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

For i = ActiveSheet.UsedRange.Rows.Count To 6 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Cells(i, 1).Resize(2).EntireRow.Insert
Cells(i + 1, 1).Value = Cells(i + 2, 2).Value
End If
Next i

With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

---
Regards,
Norman



"Dan" wrote in message
...
I have an Excel sheet with two columns of data for which I would like to
format. I need to add two rows at each change in column A (the no. of

rows
for the change to occur varies). Next I would like to copy the first

cell
in
column B where the change occurs in column A to one cell above column A
where the change occured (like a header). The following table describes
what
I would like to do.

This is the data b4 processing.
A B
6 Data A 123
7 Data A 123
8 Data B 234
9 Data B 234

This is the format that I need after processing.
7 123
8 Data A 123
9 Data A 123
10
11 234
12 Data B 234
13 Data B 234

So far, I have managed to obtain the following code to add two rows at
each
change of column A. I can't figure out how the copying and pasting is

done
via code. Could someone help? Thanks.

Sub InsertTwoRowsAtChangesInColumn()
Dim i As Long
For i = ActiveSheet.UsedRange.Rows.Count To 6 Step -1
If Cells(i, 1).Value < Cells(i - 1, 1).Value Then
Cells(i, 1).EntireRow.Insert
Cells(i, 1).EntireRow.Insert
End If
Next i
End Sub






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro - Copy/Paste Special to Next Blank Line lajohn63 New Users to Excel 2 August 27th 12 09:27 PM
Inserting last non-blank cell into a text box janabanana Excel Worksheet Functions 3 August 12th 08 10:16 PM
VBA Code- Copy & Paste in Blank Range Youlan Excel Discussion (Misc queries) 9 March 27th 08 03:22 PM
using macro to copy and paste filtered results, what if blank? priceyindevon Excel Worksheet Functions 2 December 14th 06 10:09 AM
Macro copy and paste = blank worksheet efface Excel Discussion (Misc queries) 1 April 27th 06 09:52 PM


All times are GMT +1. The time now is 07:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"