473,761 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Access VBA code to ungroup columns in excel file

126 New Member
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.


Expand|Select|Wrap|Line Numbers
  1. Sub RunMacro()
  2. On Error GoTo Err_RunMacro
  3.     Dim XL As Excel.Application
  4.     Dim xlRange As Range
  5.     Set XL = New Excel.Application
  6.     XL.Workbooks.Open "C:\Test_file1.xls"
  7.  
  8.     Dim lastrow As Long, lastcol As Long
  9.     Dim NullRange As Range
  10.     Set NullRange = Nothing
  11.  
  12.     XL.ScreenUpdating = False
  13.     XL.Calculation = xlCalculationManual
  14.  
  15.     With XL.ActiveSheet
  16.     On Error GoTo Exits
  17.     Set xlRange = .Range("A:A").SpecialCells(xlLastCell)
  18.     lastcol = xlRange.Column
  19.     .Range(.Cells(1, 1), .Cells(lastcol, 1)).SpecialCells(xlCellTypeBlanks).EntireColumn.Delete
  20.     lastrow = xlRange.Row
  21.     .Range(.Cells(1, 1), .Cells(lastrow, 1)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
  22.  
  23. Exits:
  24.     XL.ScreenUpdating = True
  25.     XL.Calculation = xlCalculationAutomatic
  26.     If Err.Description = "" Then
  27.         'MsgBox "lastrow" & lastrow
  28.         'MsgBox "lastcol" & lastcol
  29.     Else
  30.         MsgBox Err.Description
  31.     End If
  32.     End With
  33.  
  34.     XL.Workbooks("Test_file1.xls").SaveAs FileName:="C:\ExportFile\Test_file1.xls"
  35.     XL.Quit
  36.     XL.Workbooks.Close
  37.     Set XL = Nothing
  38. Exit_RunMacro:
  39.     Exit Sub
  40. Err_RunMacro:
  41.     MsgBox Err.Description
  42. End Sub
Jul 10 '08 #1
0 2999

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

Similar topics

1
1943
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...
1
2762
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...
8
3372
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:
3
11217
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...
25
2269
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",...
5
3176
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...
9
3943
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...
4
3142
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
1
10501
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...
0
9377
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,...
0
9989
jinu1996
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...
0
9811
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 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...
0
8814
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, 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...
1
7358
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 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...
0
6640
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();...
0
5266
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...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
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

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.