PDA

View Full Version : Solved: Loop through one column on any sheet in workbook....



ANBgrafix
06-17-2008, 05:39 PM
Is there a way to loop through one specific Column (say Column D) in an entire workbook (amount of sheets vary day to day) and find the last entered value, on save save this value in an ini file.

Basically when a user clicks the Save Button the Loop would find the last value of column D and save that value to this ini file:

The ini file name is C:/TC_Info.ini
[PERSONAL]
UniqueNumber="Value to be stored from this loop."

Thank you in advance.
ANB

figment
06-18-2008, 08:48 AM
dose it have to save the last value in column D for each work sheet? in the work book?

ANBgrafix
06-18-2008, 09:11 AM
Not for every worksheet.
Just the last value of column D on the last sheet of the workbook.

figment
06-18-2008, 11:19 AM
this code assumes that the user has the last page open when the click save, if you have a way of identifying the correct work sheet, then i can make the code more fool prof.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Close #2
Open "C:/TC_Info.ini" For Output As #2
Print #2, "[PERSONAL]"
Print #2, "UniqueNumber=" & Range("D1").End(xlDown).Value
Close #2
End Sub

ANBgrafix
06-18-2008, 01:24 PM
Thank You Figment! Exactly what I needed!

Charlize
06-19-2008, 04:51 AM
I would use freefile to get the filenumber. Just to be sure it's not already in use. You never know.

Charlize