Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 2nd, 2003, 07:04 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 6
How to insert blank row in Excel via VB?

Hi all, I have folowing code, and I want it to insert 2 blank rows before new bank name appears in excelsheet. Output should be like this in Excel:

ING
ING
blank row
blank row
RoyalBank
RoyalBank
RoyalBank
blank row
blank row
=================


Dim p As Integer
Dim getTT As String

' select all bank names from BANK_ACCOUNT table

getReport = "SELECT BANK_NAME FROM BANK_ACCOUNT"
Set rs = cn.Execute(getReport)

Do While Not rs.EOF ' Loop the Bank name from Bank_Account

For p = 0 To rs.EOF

getTT = rs.Fields(p)

Dim rs2 As New ADODB.Recordset
Dim getReport2 As String

' get all data(s) from REPORT table according to bank name

getReport2 = "SELECT * FROM REPORT WHERE BANK_NAME='" & getTT & "' " 'ORDER BY ACCOUNT_TYPE"
Set rs2 = cn.Execute(getReport2)

.Cells(6, 1).CopyFromRecordset rs2 'Copy recordset to Excel file starting on row 6 and col 1.

' Make every columns autofit to the data(s)
.Range(.Cells(4, 1), .Cells(20, 8)).Select
xlsApp.Selection.Columns.AutoFit

' here should insert two blank rows, butit doesn't work
.cells(i+6, 1).entirerow.insert

Next

rs.MoveNext
Loop

Reply With Quote
  #2  
Old October 2nd, 2003, 07:20 PM
mohecan mohecan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Melbourne, Australia
Posts: 212 mohecan User rank is Private First Class (20 - 50 Reputation Level)mohecan User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
The following selects rows 1 to 2, and inserts blank rows
Code:
Rows("1:2").Select
Selection.Insert shift:=xlDown
__________________
How can I soar like an eagle when
I'm flying with turkey's?

Reply With Quote
  #3  
Old October 2nd, 2003, 08:00 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 6
No ... it doesn't work

Reply With Quote
  #4  
Old October 2nd, 2003, 08:16 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,179 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 3 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Hb... I just gotta ask... it doesn't look like anything is working for you in Excel?
__________________
Fisherman

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein

Reply With Quote
  #5  
Old October 2nd, 2003, 09:23 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 6
It did appears blank rows. But not what i want it that way

Reply With Quote
  #6  
Old October 2nd, 2003, 11:11 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,179 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 10 h 3 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
Hey HB.. it's me again.. Here's what I think you should do in this instance...

Instead of copyfromrecordset... why don't you loop until rs.eof and place your information in the field where you would like it using counter variables? an example would be

dim intI as integer
dim intJ as integer

dim rsRecordset as ADODB.Recordset
dim cnConnection as ADODB.Connection
dim strSQL as string
dim XLApp as excel.application
dim xlBook as excel.workbook
dim xlSheet as excel.worksheet

set rsrecordset = new adodb.recordset
set cnconnection = new adodb.connection
set xlapp = createobject("excel.application")
cnconnection.connectionstring = "CONNECTIONSTRING"
cnconnection.open
strSQL = "SQL STRING"
rsrecordset.open strsql, cnconnection,,,
inti=1
intj=1
do until rsrecordset.eof = true
for intj = 0 to (rsrecordset.fields.count)
'Declare Excel cells as xlapp.activesheet.cells(rowindex,columnindex)
xlapp.activesheet.cells(inti, intj) = rsrecordset.fields.item(intj)
next intj
inti = inti + 1
rsrecordset.movenext
loop


A structure such as that should put your fields into particular fields. The advantage to doing that, is that if you want to move two rows ahead, then you simply increase inti by 2 before you enter the loop again.

Reply With Quote
  #7  
Old October 3rd, 2003, 02:14 PM
hbcontract hbcontract is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 59 hbcontract User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 6
Thanks ))))))) It works with your sample code

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > How to insert blank row in Excel via VB?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT