473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Insert Rows into an Excel Spreadsheet from Access using VB

8
I would like to open an existing workbook, select a work sheet and insert multiple rows at the top of the spreadsheet. Have the following code, but unsure of proper command & syntax for Insert row, and how to make it insert at row A1.

Expand|Select|Wrap|Line Numbers
  1.     With DataSheet
  2.         .Sheets(2).Select
  3.         .Rows.Insert
  4.         .Cells(1, 1).Value = txtLine1                                 
  5.         .Cells(2, 1).Value = txtLine2
  6.         .Cells(3, 1).Value = txtLine3
  7.         .Cells(4, 1).Value = txtLine4
  8.     End With
May 23 '07 #1
3 15797
NeoPa
32,556 Expert Mod 16PB
Assuming you have a variable lngXtra holding the number of extra rows required above A1.
Expand|Select|Wrap|Line Numbers
  1. With DataSheet
  2.     .Sheets(2).Select
  3.     Call .Range("A1:A" & lngXtra).EntireRow.Insert
  4.     .Cells(1, 1).Value = txtLine1                                 
  5.     .Cells(2, 1).Value = txtLine2
  6.     .Cells(3, 1).Value = txtLine3
  7.     .Cells(4, 1).Value = txtLine4
  8. End With
May 24 '07 #2
davnao
8
Assuming you have a variable lngXtra holding the number of extra rows required above A1.
Expand|Select|Wrap|Line Numbers
  1. With DataSheet
  2.     .Sheets(2).Select
  3.     Call .Range("A1:A" & lngXtra).EntireRow.Insert
  4.     .Cells(1, 1).Value = txtLine1                                 
  5.     .Cells(2, 1).Value = txtLine2
  6.     .Cells(3, 1).Value = txtLine3
  7.     .Cells(4, 1).Value = txtLine4
  8. End With
Works like a charm! Thanks!
May 25 '07 #3
NeoPa
32,556 Expert Mod 16PB
No problem.
I actually do a large amount of work in Excel too so that was an easy one ;)
May 25 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: smonczka | last post by:
I have a DTS package that needs to refresh data in 3 separate Excel spreadsheets on a daily basis. The problem is that unless I manually delete the previous day's data, it appends rather than...
3
by: Elaksomfan | last post by:
Hi, I am having trouble importing data from an excel spreadsheet into MS SQL Server 2000 using DTS Wizard. The DTS import process is successfull, no errors, but only 50 rows of approx. 1500 rows...
1
by: garry.oxnard | last post by:
Can anyone help me to solve a problem which involves switching from Access to Excel (then back to Access) programatically please? I have an Excel template which, on open, also opens an Access...
0
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
4
by: Bob | last post by:
Hi all, I'm trying to import data, modify the data then insert it into a new table. The code below works fine for it but it takes a really long time for 15,000 odd records. Is there a way I...
12
by: slinky | last post by:
Can an Excel spreadsheet or a section of one be embedded into an Access form and serve as a subform from which other parts of the Access form can get data? Thanks!
3
by: JFKJr | last post by:
Hello everyone, I am trying to insert a picture in an excel spreadsheet cell using Access VBA. The following excel VBA code is working perfectly fine and I am able to insert picture in "A1" cell....
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.