Incrementing Cells with Macros

W

wmureports

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(xlCellTypeBlanks).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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top