I have an excel file, which has columns C and D grouped together, I am trying to delete blank columns and rows from the excel file, ungroup the columns and import the file to MS Access using Access VBA code.
The following is the Access VBA code I used to delete blank columns and rows in the excel file. But, unfortunately, the resultant excel file still has two columns (C and D) grouped together, so when I am importing the file to MS Access, the table has one blank field.
Please kindly let me know what is the Access VBA code to ungroup columns in excel file. Thanks in advance. - Sub RunMacro()
-
On Error GoTo Err_RunMacro
-
Dim XL As Excel.Application
-
Dim xlRange As Range
-
Set XL = New Excel.Application
-
XL.Workbooks.Open "C:\Test_file1.xls"
-
-
Dim lastrow As Long, lastcol As Long
-
Dim NullRange As Range
-
Set NullRange = Nothing
-
-
XL.ScreenUpdating = False
-
XL.Calculation = xlCalculationManual
-
-
With XL.ActiveSheet
-
On Error GoTo Exits
-
Set xlRange = .Range("A:A").SpecialCells(xlLastCell)
-
lastcol = xlRange.Column
-
.Range(.Cells(1, 1), .Cells(lastcol, 1)).SpecialCells(xlCellTypeBlanks).EntireColumn.Delete
-
lastrow = xlRange.Row
-
.Range(.Cells(1, 1), .Cells(lastrow, 1)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
-
-
Exits:
-
XL.ScreenUpdating = True
-
XL.Calculation = xlCalculationAutomatic
-
If Err.Description = "" Then
-
'MsgBox "lastrow" & lastrow
-
'MsgBox "lastcol" & lastcol
-
Else
-
MsgBox Err.Description
-
End If
-
End With
-
-
XL.Workbooks("Test_file1.xls").SaveAs FileName:="C:\ExportFile\Test_file1.xls"
-
XL.Quit
-
XL.Workbooks.Close
-
Set XL = Nothing
-
Exit_RunMacro:
-
Exit Sub
-
Err_RunMacro:
-
MsgBox Err.Description
-
End Sub
0 2999 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mr_ocp |
last post by:
Hi friends
I need routines to create an excel file with worksheets for each
customer and a text file as well for each customer, first worksheet
would be a "Summary Report", here is the code that would get the data
for me I would appreciate if someone can add routines to create excel
and text files to it, the columns in text file need to be "|"
separated - thanks ever so much for all the help I have been getting
from this wonderful forum...
|
by: Ronny Sigo |
last post by:
Hello all,
I am trying to import the contents of an Excel sheet into my Access
Database. When clicking the button excel opens allright and does what I
programmed (the cells get updated with the value "Geimporteerd" ("Imported"
in English). So I get to the excel file alright but after changing the cells
to "Geimporteerd" Access hangs. When viewing the task manager it says that
the CPU activity is 100% and the only way to get out of this is...
|
by: mytfein |
last post by:
Hi Everyone,
Background:
Another department intends to ftp a .txt file from the mainframe, for me
to process.
The objective is to write a vb script that would be scheduled to run
daily to process this .txt file.
Goal:
I am working on a vba script to:
|
by: Lynn A. |
last post by:
I have to perform an import from an excel file to Access. The file
comes originally as a csv file. I have to delete some rows and
columns, then change the formatting of some columns. I am using
Windows 2000, Office 2000
I have been able to do everything but fill a column with zeros
Here is some of the code attached to a command button, I am using, it
works except I can't figure out how to fill down one column. In excel
it uses the...
|
by: DFS |
last post by:
I have a job to automatically import Excel data and post to database tables,
via a point-click interface. Choose-file-and-it-does-the-rest kind of
thing.
Cient stores data in columns in his sheet (I told them it should be in rows,
but that's another issue). Sometimes the sheet gets new columns added. At
that point, Access/import spec won't recognize the new columns.
DoCmd.TransferText acImportDelim, "importSpec", "TABLE_NAME",...
| |
by: hharriel |
last post by:
Hi,
I am hoping someone can help me with an issue I am having with excel
and ms access. I have collected data (which are in individual excel
files) from 49 different school districts. All districts have used the
same excel template and populated the same 32 data fields (columns). I
created one large excel file from all 49 files which gives me a master
table of 60,000 or so records. I have tried to import this master
table into access...
|
by: pic078 via AccessMonster.com |
last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files)
that remains stuck in task manager after exiting the application - you can't
reopen database after exiting as a result - I have read every post out there
and spent hours trying to figure out the problem with no success whatsoever -
I have constrained the problem to one form however, and I think it's hiding
somewhere in my code associated with this form, which is...
|
by: Melissa |
last post by:
I currently have VBA written to export query results into an Excel
file. That file is then formatted using the code below. The problem
I'm having is that it keeps throwing Error 91 (Object variable or With
block variable not set) at this part of the code:
If xlWs.Range("A3") <"" Then
xlWs.Range("A2").End(xlDown).Select
l = Selection.Row
Debug.Print "l = " & l
ElseIf xlWs.Range("A2") <"" Then
|
by: CoolFactor |
last post by:
MY CODE IS NEAR THE BOTTOM
I want to export this Access query into Excel using a command button on an Access form in the following way I describe below.
Below you will find the simple query I am trying to export to Excel using a command in an Access Form.
RowID strFY AccountID CostElementWBS
1 2008 1 7
2 2008 1 7
I want to...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |