Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default determine max number of columns in a spreadsheet

I have a macro that extracts data from different spreadsheets and puts
it into csv files. I need to insert a row into the created csv file as
a header row, this will be sequentially populated (e.g. 1,2,3,4....).
Problem I have is that I am using one macro to extract data from a
number of spreadsheets (users choice) and the number of columns varies
between spreadsheets.

I need the macro to be able to check each spreadsheet and identify the
max number of columns, remembering null values are allowed, and then
insert and sequentially number a new row at the top of the file, up to
the last column in the file.

For example,

File 1 - contains 6 columns therefore a top row would be inserted and
numbered 1-6
File 2 - contains 2 columns therefore a top row would be inserted and
numbered 1-2

Is this possible? Thanks
Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default determine max number of columns in a spreadsheet

Dim LastCol As Long

LastCol = ActiveSheet.UsedRange.Columns.Count + ActiveSheet.UsedRange.Column
- 1
Rows("1:1").Insert Shift:=xlDown
Range("A1").Select
ActiveCell.Value = 1
Selection.AutoFill Destination:=Range(Cells(1, 1), Cells(1, LastCol)),
Type:=xlFillSeries


" wrote:

I have a macro that extracts data from different spreadsheets and puts
it into csv files. I need to insert a row into the created csv file as
a header row, this will be sequentially populated (e.g. 1,2,3,4....).
Problem I have is that I am using one macro to extract data from a
number of spreadsheets (users choice) and the number of columns varies
between spreadsheets.

I need the macro to be able to check each spreadsheet and identify the
max number of columns, remembering null values are allowed, and then
insert and sequentially number a new row at the top of the file, up to
the last column in the file.

For example,

File 1 - contains 6 columns therefore a top row would be inserted and
numbered 1-6
File 2 - contains 2 columns therefore a top row would be inserted and
numbered 1-2

Is this possible? Thanks
Steve


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
determine lowest number in several columns and replace lowest numb jerry Excel Worksheet Functions 1 June 18th 08 03:19 AM
How can I determine the original creator of a spreadsheet? oscar Excel Worksheet Functions 2 December 3rd 06 09:14 PM
Increasing number of columns in spreadsheet ren422 Excel Discussion (Misc queries) 2 April 15th 05 11:57 AM
How do I limit number of rows and columns on a spreadsheet Valser New Users to Excel 3 February 12th 05 10:31 PM
Adding two columns to determine number of days to pay Katherine[_4_] Excel Programming 3 August 18th 04 08:18 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"