PC Review


Reply
Thread Tools Rate Thread

Column is overwritten

 
 
webels
Guest
Posts: n/a
 
      16th Aug 2010
Hi

I have the following code to update a worksheet on a daily basis.

I would like to create a column with a row heading of Reviewed. in
column M.

This is fine but when I rerun the macro below new data overwrites this
column which will be left blank or have a Y for reviewed.

Code as follows

Sub TIPS()



ChDir "M:\Statdata"
Workbooks.OpenText Filename:="M:\Statdata\EDDTIPS.TXT",
Origin:=xlMSDOS, _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1),
Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)),
TrailingMinusNumbers:=True, _
Local:=True '<- this decides date interpretation





Range("A1:M500").Select
Selection.Copy

Workbooks.Open Filename:= _
"G:\Microbiology\Registrars\TIPSICU.xls ", Origin:=xlWindows
Sheets("Main").Select

Range("A65536").End(xlUp).Offset(1, 0).Select

ActiveSheet.Paste

Cells.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

Columns("B:B").Select


Set Rng = ActiveSheet
R = 1
N = 1
With Rng
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
Do While N <= LastRow
If R Mod 500 = 0 Then
Application.StatusBar = "Processing Row: " & Format(R,
"#,##0")
End If

V = .Range("B" & R).Value
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Note that COUNTIF works oddly with a Variant that is equal to
'vbNullString.
' Rather than pass in the variant, you need to pass in vbNullString
'explicitly.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If V = vbNullString Then
If Application.WorksheetFunction. _
CountIf(.Columns(1), vbNullString) > 1 Then


.Rows(R).Delete
End If
Else
Next_V = .Range("B" & (R + 1)).Value
If V = Next_V Then
ThisDate = .Range("J" & R).Value


NextDate = .Range("J" & (R + 1)).Value
If ThisDate < NextDate Then
.Rows(R + 1).Delete
''? here

Else
.Rows(R).Delete
End If
Else
R = R + 1
End If
End If
N = N + 1
Loop
End With
Cells.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

'header:xlYes refers to the fact that there is a header row


ActiveWorkbook.Save

Windows("TIPSICU.xls").Activate
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

Windows("Macro.xls").Activate
Application.DisplayAlerts = False
Application.Quit



End Sub



Would anyone have any ideas on this one..

Many thanks
Eddie




 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      17th Aug 2010
Your explanation is difficult to understand...
In general what does the code do?
Did you write the code?

Do you want to create a column?
or
Do something to an existing column?
or
Not do something to an existing column?
or ?
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasForXL

..
..
..

"webels" <(E-Mail Removed)>
wrote in message
news:b9f38d99-9adf-4e66-b6ad-(E-Mail Removed)...
Hi

I have the following code to update a worksheet on a daily basis.

I would like to create a column with a row heading of Reviewed. in
column M.

This is fine but when I rerun the macro below new data overwrites this
column which will be left blank or have a Y for reviewed.

Code as follows

Sub TIPS()



ChDir "M:\Statdata"
Workbooks.OpenText Filename:="M:\Statdata\EDDTIPS.TXT",
Origin:=xlMSDOS, _
StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
Comma:=False _
, Space:=False, Other:=True, OtherChar:="|",
FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1),
Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)),
TrailingMinusNumbers:=True, _
Local:=True '<- this decides date interpretation





Range("A1:M500").Select
Selection.Copy

Workbooks.Open Filename:= _
"G:\Microbiology\Registrars\TIPSICU.xls ", Origin:=xlWindows
Sheets("Main").Select

Range("A65536").End(xlUp).Offset(1, 0).Select

ActiveSheet.Paste

Cells.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

Columns("B:B").Select


Set Rng = ActiveSheet
R = 1
N = 1
With Rng
LastRow = .Range("B" & Rows.Count).End(xlUp).Row
Do While N <= LastRow
If R Mod 500 = 0 Then
Application.StatusBar = "Processing Row: " & Format(R,
"#,##0")
End If

V = .Range("B" & R).Value
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Note that COUNTIF works oddly with a Variant that is equal to
'vbNullString.
' Rather than pass in the variant, you need to pass in vbNullString
'explicitly.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If V = vbNullString Then
If Application.WorksheetFunction. _
CountIf(.Columns(1), vbNullString) > 1 Then


.Rows(R).Delete
End If
Else
Next_V = .Range("B" & (R + 1)).Value
If V = Next_V Then
ThisDate = .Range("J" & R).Value


NextDate = .Range("J" & (R + 1)).Value
If ThisDate < NextDate Then
.Rows(R + 1).Delete
''? here

Else
.Rows(R).Delete
End If
Else
R = R + 1
End If
End If
N = N + 1
Loop
End With
Cells.Select
Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
_
DataOption1:=xlSortNormal

'header:xlYes refers to the fact that there is a header row


ActiveWorkbook.Save

Windows("TIPSICU.xls").Activate
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True

Windows("Macro.xls").Activate
Application.DisplayAlerts = False
Application.Quit



End Sub



Would anyone have any ideas on this one..

Many thanks
Eddie




 
Reply With Quote
 
webels
Guest
Posts: n/a
 
      17th Aug 2010
On Aug 17, 5:46*am, "Jim Cone" <james.cone...@comcast.netXXX> wrote:
> Your explanation is difficult to understand...
> In general what does the code do?
> Did you write the code?
>
> Do you want to create a column?
> or
> Do something to an existing column?
> or
> Not do something to an existing column?
> or ?
> --
> Jim Cone
> Portland, Oregon *USAhttp://tinyurl.com/ExtrasForXL
>
> .
> .
> .
>
> "webels" <eid...@gmail.com>
> wrote in messagenews:b9f38d99-9adf-4e66-b6ad-(E-Mail Removed)...
> Hi
>
> I have the following code to update a worksheet on a daily basis.
>
> I would like to create a column with a row heading of Reviewed. in
> column M.
>
> This is fine but when I rerun the macro below new data overwrites this
> column which will be left blank or have a Y for reviewed.
>
> Code as follows
>
> Sub TIPS()
>
> ChDir "M:\Statdata"
> * * Workbooks.OpenText Filename:="M:\Statdata\EDDTIPS.TXT",
> Origin:=xlMSDOS, _
> * * * * StartRow:=1, DataType:=xlDelimited,
> TextQualifier:=xlDoubleQuote, _
> * * * * ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False,
> Comma:=False _
> * * * * , Space:=False, Other:=True, OtherChar:="|",
> FieldInfo:=Array(Array(1, 1 _
> * * * * ), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1),
> Array(6, 1), Array(7, 1), Array(8, 1), _
> * * * * Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1)),
> TrailingMinusNumbers:=True, _
> Local:=True * '<- this decides date interpretation
>
> Range("A1:M500").Select
> * * Selection.Copy
>
> * * Workbooks.Open Filename:= _
> * * * * "G:\Microbiology\Registrars\TIPSICU.xls ", Origin:=xlWindows
> Sheets("Main").Select
>
> Range("A65536").End(xlUp).Offset(1, 0).Select
>
> ActiveSheet.Paste
>
> * * Cells.Select
> * * Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
> Header:=xlGuess, _
> * * * * OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
> _
> * * * * DataOption1:=xlSortNormal
>
> * * Columns("B:B").Select
>
> * *Set Rng = ActiveSheet
> R = 1
> N = 1
> With Rng
> * *LastRow = .Range("B" & Rows.Count).End(xlUp).Row
> * *Do While N <= LastRow
> * * * If R Mod 500 = 0 Then
> * * * * *Application.StatusBar = "Processing Row: " & Format(R,
> "#,##0")
> * * * End If
>
> * * * V = .Range("B" & R).Value
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> ' Note that COUNTIF works oddly with a Variant that is equal to
> 'vbNullString.
> ' Rather than pass in the variant, you need to pass in vbNullString
> 'explicitly.
> '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
> * * * If V = vbNullString Then
> * * * * *If Application.WorksheetFunction. _
> * * * * * * CountIf(.Columns(1), vbNullString) > 1 Then
>
> * * * * * * .Rows(R).Delete
> * * * * *End If
> * * * Else
> * * * * *Next_V = .Range("B" & (R + 1)).Value
> * * * * *If V = Next_V Then
> * * * * * * ThisDate = .Range("J" & R).Value
>
> * * * * * * NextDate = .Range("J" & (R + 1)).Value
> * * * * * * If ThisDate < NextDate Then
> * * * * * * * *.Rows(R + 1).Delete
> * * * * * * * *''? here
>
> * * * * * * Else
> * * * * * * * *.Rows(R).Delete
> * * * * * * End If
> * * * * *Else
> * * * * * * R = R + 1
> * * * * *End If
> * * * End If
> * * * N = N + 1
> * *Loop
> End With
> Cells.Select
> * * Selection.Sort Key1:=Range("B2"), Order1:=xlAscending,
> Header:=xlYes, _
> * * * * OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom,
> _
> * * * * DataOption1:=xlSortNormal
>
> 'header:xlYes refers to the fact that there is a header row
>
> ActiveWorkbook.Save
>
> Windows("TIPSICU.xls").Activate
> * * Application.DisplayAlerts = False
> * * ActiveWorkbook.Close
> * * Application.DisplayAlerts = True
>
> * *Windows("Macro.xls").Activate
> * * Application.DisplayAlerts = False
> * * Application.Quit
>
> End Sub
>
> Would anyone have any ideas on this one..
>
> Many thanks
> Eddie


HI Jim
Thanks for your reply.

The code firstly pulls a test file from a folder and adds it to an
existing worksheet adding it to the next available space at the bottom
of the worksheet (this is the piece i wrote myself)

Now the bit i didn't write. The text file will have duplicate records
which I wish to eliminate. Based on a unique number on column B and an
extract date on Column J. I only keep unique records ie no duplicate
numbers in Col B and the oldest date (original extract date) on col J.

What I am hoping to get is a review Column on Col M which is tagged
with a Y when it has been seen by the reviewer. However when I set up
this column the Y's get blanked as new data is being added. I hope
this is clear and again thank you for looking at this for me.

Eddie
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      17th Aug 2010
Maybe...

If ThisDate < NextDate Then
'Column M cell must be blank
If Len(.Cells(R + 1, 13)) = 0 Then .Rows(R + 1).Delete
''? here
Else
If Len(.Cells(R, 13)) = 0 Then .Rows(R).Delete
End If
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/XLCompanion

..
..
..

"webels" <(E-Mail Removed)>
wrote in message
news:75b6119f-7352-45ad-ac9e-(E-Mail Removed)...

HI Jim
Thanks for your reply.

The code firstly pulls a test file from a folder and adds it to an
existing worksheet adding it to the next available space at the bottom
of the worksheet (this is the piece i wrote myself)

Now the bit i didn't write. The text file will have duplicate records
which I wish to eliminate. Based on a unique number on column B and an
extract date on Column J. I only keep unique records ie no duplicate
numbers in Col B and the oldest date (original extract date) on col J.

What I am hoping to get is a review Column on Col M which is tagged
with a Y when it has been seen by the reviewer. However when I set up
this column the Y's get blanked as new data is being added. I hope
this is clear and again thank you for looking at this for me.

Eddie
 
Reply With Quote
 
webels
Guest
Posts: n/a
 
      17th Aug 2010
On Aug 17, 3:46*pm, "Jim Cone" <james.cone...@comcast.netXXX> wrote:
> Maybe...
>
> * * * *If ThisDate < NextDate Then
> * * * * *'Column M cell must be blank
> * * * * * If Len(.Cells(R + 1, 13)) = 0 Then .Rows(R + 1).Delete
> * * * * * ''? here
> * * * *Else
> * * * * * If Len(.Cells(R, 13)) = 0 Then .Rows(R).Delete
> * * * *End If
> --
> Jim Cone
> Portland, Oregon *USAhttp://tinyurl.com/XLCompanion
>
> .
> .
> .
>
> "webels" <eid...@gmail.com>
> wrote in messagenews:75b6119f-7352-45ad-ac9e-(E-Mail Removed)...
>
> HI Jim
> Thanks for your reply.
>
> The code firstly pulls a test file from a folder and adds it to an
> existing worksheet adding it to the next available space at the bottom
> of the worksheet (this is the piece i wrote myself)
>
> Now the bit i didn't write. The text file will have duplicate records
> which I wish to eliminate. Based on a unique number on column B and an
> extract date on Column J. I only keep unique records ie no duplicate
> numbers in Col B and the oldest date (original extract date) on col J.
>
> What I am hoping to get is a review Column on Col M which is tagged
> with a Y when it has been seen by the reviewer. However when I set up
> this column the Y's get blanked as new data is being added. I hope
> this is clear and again thank you for looking at this for me.
>
> Eddie


Thanks Jim for this idea-I have it working with slight alterations to
the code.

This was really helpful

Eddie
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overwritten Fil quad Microsoft Excel Misc 3 14th Nov 2008 07:32 PM
overwritten my MBR dave the second Windows XP Setup 5 2nd Apr 2008 02:36 PM
New record overwritten on old column chooriang Microsoft Access Getting Started 5 18th Nov 2006 12:39 AM
overwritten sali Windows XP Security 2 24th Feb 2006 08:16 AM
.XLB OverWritten Alex J Microsoft Excel Misc 1 18th Dec 2004 10:45 PM


Features
 

Advertising
 

Newsgroups
 


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