Copy data and control error

ashani

Active Member
Joined
Mar 14, 2020
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hi,

I wonder if someone could please guide me - I'm using the following Macro coding to copy data from one workbook to another - however the another workbook is shared across different campuses so if any other use in that workbook then the error message comes up. What I'm looking for is - if someone is in the other workbook then user receives the message pop up to say "Another user is in the workbook, would you like to save or wait" - If user select save then it saves as normal and if click retry and try again to copy the data over to another workbook and then save. Here's my current coding.

Many thanks in advance.

VBA Code:
ub CopyToMI()
    Dim Cel As Range
    Dim wsc As Worksheet, wst As Worksheet
    Dim wbc As Workbook, wbt As Workbook
    Dim arrc, arrt
    Dim k&, j&, m&
    Dim i As Variant

    On Error GoTo myerror
    Set wbc = ThisWorkbook
    Set wsc = wbc.Worksheets("dashboard")
    arrc = wsc.[B8:D10]
    k = 1: m = 0
    ReDim arrt(1, UBound(arrc, 1) * (UBound(arrc, 2)))
    For i = 1 To UBound(arrc, 1)
        For j = 1 To UBound(arrc, 2)
            arrt(k, m + j) = arrc(i, j)
        Next j
        m = m + UBound(arrc, 2)
        
    Next i
    Application.ScreenUpdating = False
    Set wbt = Workbooks.Open("C:\Users\Desktop\Test.xlsx", ReadOnly:=False, Password:="abc")
    Set wst = wbt.Worksheets("Sheet1")
    i = Application.Match(UCase(wsc.[D3]), wst.[A1:A82], 0)
'Search Text Not Found
    If IsError(i) Then Err.Raise 744
    wst.Cells(CLng(i), 2).Resize(UBound(arrt, 1), UBound(arrt, 2)) = arrt

    wbt.Close True
    Set wbt = Nothing

myerror:
    If Not wbt Is Nothing Then wbt.Close False
    Application.ScreenUpdating = True
    If Err <> 0 Then MsgBox (Error(Err)), 48, "Select Your Campus"
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
hi everyone,

any possibilty to achieve the above objective ?

Many thanks,
 
Upvote 0

Forum statistics

Threads
1,215,706
Messages
6,126,340
Members
449,311
Latest member
accessbob

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