Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Incrementing Cells with Macros

Ok, so heres what I am doing. I am merging about 500 xls files into
ONE file using a macro.
Now, I get all the files to import just fine.

Heres the code.

SaveDriveDir = CurDir
MyPath = "C:\Test"
ChDrive MyPath
ChDir MyPath
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If
Application.ScreenUpdating = False
Set basebook = ThisWorkbook
'basebook.Worksheets(1).Cells.Clear
'clear all cells on the first sheet
rnum = 8

Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.DisplayAlerts = False
lrow = LastRow(mybook.Sheets(1))
Set sourceRange = mybook.Worksheets(1).Range("C8:IV" & lrow)
SourceRcount = sourceRange.Rows.Count
Set destrange = basebook.Worksheets(1).Cells(rnum, "C")

sourceRange.Copy destrange

mybook.Close False

ActiveSheet.Range("C:C").SpecialCells(xlCellTypeBl anks).EntireRow.Delete
rnum = rnum + SourceRcount
FNames = Dir()
Loop
ChDrive SaveDriveDir
ChDir SaveDriveDir
Application.ScreenUpdating = True
End Sub


Ok, that basically Copies all the information and starts pasting the
information into Cell C8 and goes all the way down till its finished...

Now what I want to edit is this. I want to make Column B a "count
records column" The value in this column will increment with each
record that is imported. So itll look something like this

Record #: ID Name:
1 45 John
2 89 Joe
3 24 Joel

And so On. The Records column isnt imported with the data, i want it
to be inserted each time in front of the import data on each row with
the # of which record it is. Your help is appreciated

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
Incrementing numbers in cells Andrew Morine Excel Worksheet Functions 1 August 26th 08 02:11 AM
how do I disable the option that keeps incrementing cells by 1? Excel-novice Excel Worksheet Functions 1 October 14th 06 05:21 PM
incrementing with blank cells in between alexmace Excel Discussion (Misc queries) 2 March 9th 06 11:34 PM
Newbie needs help with incrementing a series of cells mikeod Excel Worksheet Functions 5 November 16th 05 08:19 PM
incrementing cells withina formula in VB Paul Excel Programming 1 June 14th 04 04:48 PM


All times are GMT +1. The time now is 02:08 AM.

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"