Code Not Working - Suggestions?

MitzDriver

Board Regular
Joined
Aug 23, 2010
Messages
60
For the most part all this works. However the third "withthisworkbook" section. it does not work at all.

Suggestions for changes will be very appreciated.

Code:
Private Sub CommandButton1_Click()
'Copy "Balance Forward" to workbook DataFile.xls
Dim TargetWB As String
Dim ThisPath As String
Dim wkbDst  As Workbook
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
 
        On Error Resume Next
        Set wkbDst = Workbooks("DataFile.xls")
        If Err.Number Then Set wkbDst = Workbooks.Open("C:\Bingo Files\DataFile.xls")
        On Error GoTo 0
 
    [COLOR=lime]' this part works[/COLOR]
    With ThisWorkbook.Worksheets("103").Range("P68:P70")
        wkbDst.Worksheets("Sheet1").Range("A1").Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
    [COLOR=lime]' this part works[/COLOR]
    With ThisWorkbook.Worksheets("104-A").Range("E26")
        wkbDst.Worksheets("Sheet1").Range("B" & Lr + 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
    [COLOR=red]' this part DOES NOT WORK[/COLOR]
    With ThisWorkbook.Worksheets("104-D").Range("K12")
        wkbDst.Worksheets("Sheet1").Range("C" & Lr + 1).Resize(.Rows.Count, .Columns.Count).Value = .Value
    End With
 
    wkbDst.Close SaveChanges:=True
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You don't appear to have assigned a value to Lr. Maybe

Code:
wkbDst.Worksheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Offset(1).Resize(.Rows.Count, .Columns.Count).Value = .Value
 
Upvote 0
Sorry, that's totally against the rules. Spill the beans! :)
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top