473,435 Members | 1,704 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,435 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 15801
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.