View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 692
Default Updating a database with macro

Lathan,

Be sure to:
Dim lrw1 as Long
The error indicates that excel doesn't recognize the workbook and/or the
worksheet name(s)
Check that the workbook name is "newdata" and the worksheet name is
"NewStuff"

And make sure excel sees it as a single line:
lrw1 = _
Workbooks("newdata").Sheets("NewStuff").Cells(Rows .Count,"A").End(xlUp).Row
--
steveB

Remove "AYN" from email to respond
"lalthan" wrote in
message ...

Hello Steve,
I've tried out the macro and it goes like this.Here the workbook where
the datas are entered regularly is called "newdata" and the sheet is
called "NewStuff". This is where all the new datas are entered.
This workbook is to be updated to the workbook called "Management
Information System_2005" and the name of the sheet is "Raw Data". Raw
Data has around 46 Column Headers (Names, Codes, City, Date of Entry,
Currency Amount etc) and about 3000 rows of informations consisting of
text, numbers, strings, alphanumbericals etc.

"NewStuff" sheet contains almost the same thing as "Raw Data". New
entries are entered here in this sheet and they are to be updated to
the Raw Data sheet at the end of the month.

I am still getting errors now. Can you please see where I am going
wrong.



------------------------------------------------------
Sub CheckReplaceData()

' find number of rows in data workbook.
lrw1 = Workbooks("newdata").Sheets("NewStuff").Cells(Rows .Count,
"A").End(xlUp).Row

'(NOTE: IN THE ABOVE CODE, I am getting a "Runtime Error 9, Subscript
out of Range" Message)

' loop through NewStuff - assuming that New stuff starts on row 2 and
has 8
'columns of data
For rw1 = 2 To lrw1
If WorksheetFunction.CountIf(Workbooks("Management Information
System_2005").Sheets("Raw Data").Columns(1),
Workbooks("newdata").Sheets("NewStuff").Cells(rw1, 1)) = 0 Then
' your code to add a new line
Dim lrw As Long
' find last used row in Old data and add 1 to get next empty row
lrw = Workbooks("Management Information System_2005").Sheets("Raw
Data").Cells(Rows.Count, "A").End(xlUp).Row + 1

'Copy and paste new data to old stuff - copies entire row and pastes
first
'cell in empty row
' you could alter the code to copy a range and paste it.
Workbooks("newdata").Sheets("NewStuff").Rows(rw1). Copy _
Destination:=Workbooks("Management Information
System_2005").Sheets("Raw Data").Range("A" & lrw)

Else: MacroCheckReplace
End If
Next
End Sub
-----------------------------------------------------------------------------
Sub MacroCheckReplace()
' row to check and change in OldStuff
rw2 =
WorksheetFunction.Match(Workbooks("newdata").Sheet s("NewStuff").Cells(rw1,
1), Workbooks("Management Information System_2005").Sheets("Raw
Data").Columns(1), 0)

' loop each column
For col1 = 2 To 8
If Workbooks("newdata").Sheets("NewStuff").Cells(rw1, col1) < _
Workbooks("Management Information System_2005").Sheets("Raw
Data").Cells(rw2, col1) Then
Workbooks("Management Information System_2005").Sheets("Raw
Data").Cells(rw2, col1) = _
Workbooks("newdata").Sheets("NewStuff").Cells(rw1, col1)
Else ' put in other code if the cells are equal
End If
Next

End Sub

'Sub InsertRow()
'Dim Rng
'Rng = InputBox("Enter number of rows required.")
'Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(Rng - 1, 0)).Select
'Selection.EntireRow.Insert
'End Sub


--
lalthan
------------------------------------------------------------------------
lalthan's Profile:
http://www.excelforum.com/member.php...o&userid=10557
View this thread: http://www.excelforum.com/showthread...hreadid=397222