ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Incrementing Cells with Macros (https://www.excelbanter.com/excel-programming/365708-incrementing-cells-macros.html)

wmureports

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



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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com