Solved Copy and Insert Of Title in same sheet

August 23, 2011 at 09:10:27
Specs: Windows XP
Hello,
I am facing a problem in writing code for copying a title in same excel sheet. As the data is important i do not want manual intervention which could make the outcome wrong. The sheet contains database from column A to D and column A contains the title as name of the company which is repeated from A1:A10(range could change too) and then there is another company same goes on. I need to put tittle as per the data in A1 and so on Kindly help me out.

See More: Copy and Insert Of Title in same sheet

Report •


#1
August 24, 2011 at 13:18:29
I'm kind of confused as to where you want this Title placed.

I also don't know what you mean by:

"I need to put tittle as per the data in A1 and so on"

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
August 24, 2011 at 23:51:13
Equities Buy Price Sell Price
DLF 105 106
DLF 106 107
DLF 107 108
DLF 108 109
DLF 109 110
DLF 110 111
RIL 555 556
RIL 556 557
RIL 557 558
RIL 558 559
RIL 559 560
RIL 560 561
RIL 561 562
Sterlite 250 251
Sterlite 251 252
Sterlite 252 253
Sterlite 253 254
Sterlite 254 255
Sterlite 255 256
Sterlite 256 257

The above is raw data received.

The result required is as follows:

Equities Buy Price Sell Price
DLF 105 106
DLF 106 107
DLF 107 108
DLF 108 109
DLF 109 110
DLF 110 111
Equities Buy Price Sell Price
RIL 556 557
RIL 557 558
RIL 558 559
RIL 559 560
RIL 560 561
RIL 561 562
Equities Buy Price Sell Price
Sterlite 250 251
Sterlite 251 252
Sterlite 252 253
Sterlite 253 254
Sterlite 254 255
Sterlite 255 256
Sterlite 256 257

In the above if u see the title is repeated at every equity changed...i am unable to find any macro also for this as one equity can be repeated any number of times...so please if u can help me now...i hope its clear now...


Report •

#3
August 25, 2011 at 05:07:17
✔ Best Answer
Sub InsertTitles()
 lastRw = Range("A" & Rows.Count).End(xlUp).Row
  For rw = lastRw To 2 Step -1
   If Cells(rw, 1) <> Cells(rw - 1, 1) Then
    Rows(1).EntireRow.Copy
    Rows(rw).Insert shift:=xlDown
    rw = rw - 1
   End If
  Next
 Rows(1).Delete
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
September 3, 2011 at 10:31:56
Thanks for providing a suitable answer but further i have a data which needs to be segragated..For Ex..the below is raw database
Reliance
Reliance Buy Sell
Reliance 20000 10000
Reliance 14000 16000
Reliance 13000 70000
Reliance 10000 0
Reliance 70000 0
Reliance 14000 16000
Reliance 20000 10000
Reliance 13000 7000
Reliance 0 4000
Reliance 0 2500
TCS
TCS Buy Sell
TCS 75000 0
TCS 24000 0
TCS 12000 10000
TCS 5000 8000
TCS 12000 10000
TCS 5000 8000
TCS 3000 3000
The problem in the above is i need to find manually the top buy and top sell and then add the titles so the return file would be as below:
Reliance
Reliance Buy Sell
Reliance 20000 10000
Reliance 14000 16000
Reliance 13000 70000
Reliance 10000 0
Reliance 70000 0
Reliance
Reliance Buy Sell
Reliance 14000 16000
Reliance 20000 10000
Reliance 13000 7000
Reliance 0 4000
Reliance 0 2500
TCS
TCS Buy Sell
TCS 75000 0
TCS 24000 0
TCS 12000 10000
TCS 5000 8000
TCS
TCS Buy Sell
TCS 12000 10000
TCS 5000 8000
TCS 3000 3000
Kindly help me out for writting in vba in excel again..please...

Report •


Ask Question