Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default VBA to Identify changes in row1

Hello,

I inherit database files in Excel format from others. Because they are the
owner of the files, they sometimes modify the Header (in row 1) without
informing others.

Im intending use a macro to verify if any additional new header has been
added or old header being removed.

Example todays file header in row 1 is:
A1 = SupplierCode
B1 = SupName
C1 = SupGroup
D1 = Product
E1 = AltProduct
F1 = Description
€¦€¦etc

Then, tomorrow, he could change by slotting in an extra header called
€śProduct Sales€ť right in the middle of any column.

I just need a very simple code. Just to get VBA to verify from cell A1 right
across to the last cell in row 1. Honestly, I dont even need to know which
specific cell in row1 has been changed. All I need is for VBA to €śtell me
there is a change€ť when I run the code.

Many of my other database suffers the same calamity. I dont mind updating
by re-typing the header into your VBA codes. All I need is a way to spot such
changes.

Thanks a lot.

I'm a VBA rookie.

--
Edmund
(Using Excel XP)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to Identify changes in row1


can you not protect the cells you don't want changed??

You could hilight the cells that are allowed to be changed and then
format.cells ,protection, uncheck locked

then protect the sheet, tools,protect sheet

the cells that are protected now cannot be changed


--
davesexcel


------------------------------------------------------------------------
davesexcel's Profile: http://www.excelforum.com/member.php...o&userid=31708
View this thread: http://www.excelforum.com/showthread...hreadid=540913

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA to Identify changes in row1

I'll bet this is a unique solution.
1) Being a new user, you may wish to investigate 'Option Explicit'. A
good help for them typos.
2) Since we are testing between sessions, we need to have some method
to hold the data over from one session to the next. You suggested
within a macro, so that's what I'll use.
3) We need one macro to record our data from one session and another
macro to compare that data to all later sessions until we find a
change. Then, we give the first macro another shot to re-record the
new data.
4) But wait. Instead of recording just the data, we can record the
whole, new macro so copying and pasting is VERY simple.
5) I've made good use of the .debug utiltity to create the second
macro from the first.

Start off as follows.
Option Explicit

Sub RecordHeaders()
Dim cell As Range

Debug.Print "Sub compheaders()"
For Each cell In Range("$A$1:" & [IV1].End(xlToLeft).Offset(0,
4).Address)
Debug.Print "If range(""" & cell.Address & """).value < """;
cell.Value; """ then msgbox ""Change in " & cell.Address & """"
Next cell
Debug.Print "end sub"
End Sub

Run this first macro and the code for the new macro appears in the
immediate pane (choose View\Immediate Window (^G) if you don't know
about this).

Next, copy the code from the immediate window and insert it into your
main macro pane (replacing the old compheaders() if it exists). Then
run compheaders() until it shows you a change.

6) If you want to be a bit more advanced, write your code so there is
no new macro created. Store the data some other way. A couple of
suggestions ...
A) Please investigate the 'Open' statement to open a flat file to
store the header data from session to session. Other helpful
statements, if you go this route, may be 'Close', 'Line Input', and
'Write'.
B) Manually or programatically copy the header row to the
clipboard, open a new workbook, paste the header row and save the file.
Then, when the old workbook is opened (use the Private Sub
Workbook_Open() snippet provided for each workbook), compare the two
headers. This may be more elegant, but more difficult. Use the
'Record New Macro' facility to help.

Personally, I prefer the solution given. Seem really simple.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default VBA to Identify changes in row1

Dear jacod,

You are a fantastic! Thank you so very much for sharing in such great detail
& clarity.

Besides getting my answer, youve given me a Big Value-Added Bonus with such
an excellent method of achieving the task. It was a priceless eye-opener to a
rookie like me. Thank you for whetting my appetite for VBA.

Thanks to all the great people like you, Im very motivated to learn more of
VBA from today onwards!

--
Edmund
(Using Excel XP)


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
How to change the row1 content of the existing excel file automically tlee Excel Worksheet Functions 2 April 28th 09 01:47 AM
How to get row2 value into row1 in calculated Field Column in pivo arun Excel Discussion (Misc queries) 0 March 31st 09 08:50 AM
VBA dynamically format Row1 Liz Excel Programming 2 January 6th 06 09:15 PM
how to identify sarans Excel Worksheet Functions 7 October 26th 05 09:15 PM
Trying to identify what is not there Robert[_14_] Excel Programming 2 October 9th 04 11:10 AM


All times are GMT +1. The time now is 11:23 AM.

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

About Us

"It's about Microsoft Excel"