Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to insert data from another sheet stops working

Hello,

I want to thank everyone for their help on this in advance!

I am currently working on a budget program in which I have a module
called InsertAdjustments. I call the module to insert adjustments from
a worksheet named Manual Adjustments which populates each sheet.
Unfortunately the code works for some sheets, but not others. It even
stops half way through one of the sheets. I have been looking on this
site to find some answers but haven't found anything yet.

Please help! My code was based off of a posting by "Dave". Here's
the code I'm currently using:

Sub InsertAdjustments()

Const cMasterKeyColumn = 3 'column number used for comparison
Const cUpdateKeyColumn = 3 'column number used for comparison

Dim wsMaster As Worksheet 'destination worksheet
Dim wsUpdate As Worksheet 'local worksheet
Dim rngMasterSearchRange As Range 'rng in master to search
Dim rngFindResult As Range 'rng in local to find
Dim lMasterLastRow As Long 'last row when appending in master
Dim lastrow As Long
Dim lUpdateRow As Long 'row to update copied from local sheet

Set wsMaster = ThisWorkbook.Worksheets("ManualAdjustments")
Set wsUpdate = ThisWorkbook.ActiveSheet
lastrow = ActiveSheet.Cells(Rows.count, "C").End(xlUp)(2).Row
Set rngMasterSearchRange = wsMaster.Range("C2:C" & lastrow)
lUpdateRow = 8

Do While wsUpdate.Cells(lUpdateRow, cUpdateKeyColumn).Value < ""
Set rngFindResult = rngMasterSearchRange.Find( _
What:=wsUpdate.Cells(lUpdateRow, cUpdateKeyColumn).Value, _
LookIn:=xlValues, _
MatchCase:=False)

If rngFindResult Is Nothing Then
Else 'value found, so update values
wsUpdate.Cells(lUpdateRow, 6).Value =
wsMaster.Cells(rngFindResult.Row, 6).Value
wsUpdate.Cells(lUpdateRow, 7).Value =
wsMaster.Cells(rngFindResult.Row, 7).Value
wsUpdate.Cells(lUpdateRow, 8).Value =
wsMaster.Cells(rngFindResult.Row, 8).Value
End If
'move to next row on Update sheet:
lUpdateRow = lUpdateRow + 1
Application.CutCopyMode = False
Loop
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Macro to insert data from another sheet stops working

It's ok, I figured it out - I set "lastrow" to "ActiveSheet" when it
should have been "wsMaster".

Thanks anyways,

Nats


Nats wrote:
Hello,

I want to thank everyone for their help on this in advance!

I am currently working on a budget program in which I have a module
called InsertAdjustments. I call the module to insert adjustments from
a worksheet named Manual Adjustments which populates each sheet.
Unfortunately the code works for some sheets, but not others. It even
stops half way through one of the sheets. I have been looking on this
site to find some answers but haven't found anything yet.

Please help! My code was based off of a posting by "Dave". Here's
the code I'm currently using:

Sub InsertAdjustments()

Const cMasterKeyColumn = 3 'column number used for comparison
Const cUpdateKeyColumn = 3 'column number used for comparison

Dim wsMaster As Worksheet 'destination worksheet
Dim wsUpdate As Worksheet 'local worksheet
Dim rngMasterSearchRange As Range 'rng in master to search
Dim rngFindResult As Range 'rng in local to find
Dim lMasterLastRow As Long 'last row when appending in master
Dim lastrow As Long
Dim lUpdateRow As Long 'row to update copied from local sheet

Set wsMaster = ThisWorkbook.Worksheets("ManualAdjustments")
Set wsUpdate = ThisWorkbook.ActiveSheet
lastrow = ActiveSheet.Cells(Rows.count, "C").End(xlUp)(2).Row
Set rngMasterSearchRange = wsMaster.Range("C2:C" & lastrow)
lUpdateRow = 8

Do While wsUpdate.Cells(lUpdateRow, cUpdateKeyColumn).Value < ""
Set rngFindResult = rngMasterSearchRange.Find( _
What:=wsUpdate.Cells(lUpdateRow, cUpdateKeyColumn).Value, _
LookIn:=xlValues, _
MatchCase:=False)

If rngFindResult Is Nothing Then
Else 'value found, so update values
wsUpdate.Cells(lUpdateRow, 6).Value =
wsMaster.Cells(rngFindResult.Row, 6).Value
wsUpdate.Cells(lUpdateRow, 7).Value =
wsMaster.Cells(rngFindResult.Row, 7).Value
wsUpdate.Cells(lUpdateRow, 8).Value =
wsMaster.Cells(rngFindResult.Row, 8).Value
End If
'move to next row on Update sheet:
lUpdateRow = lUpdateRow + 1
Application.CutCopyMode = False
Loop
End Sub


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
Macro stops working when sheet is protected RefLib1978 Excel Discussion (Misc queries) 3 May 28th 09 03:57 PM
SheetBeforeRightClick stops firing after macro repopulates sheet MAB Excel Programming 7 July 22nd 06 02:51 PM
SheetBeforeRightClick stops firing after macro repopulates sheet MAB Excel Programming 1 July 21st 06 09:16 PM
macro randomly stops working johnlengacher Excel Programming 1 February 2nd 06 06:44 PM
macro stops copying sheets into a book after the 11th sheet MISMitch Excel Programming 1 October 22nd 03 05:27 PM


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

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"