+ Reply to Thread
Results 1 to 18 of 18

VBA_Help

Hybrid View

Nyay VBA_Help 06-16-2024, 11:57 AM
torachan Re: VBA_Help 06-16-2024, 12:21 PM
Nyay Re: VBA_Help 06-16-2024, 12:23 PM
Nyay Re: VBA_Help 06-16-2024, 10:01 PM
Nyay Re: VBA_Help 06-17-2024, 07:11 AM
kvsrinivasamurthy Re: VBA_Help 06-17-2024, 09:47 AM
Nyay Re: VBA_Help 06-17-2024, 09:53 AM
kvsrinivasamurthy Re: VBA_Help 06-17-2024, 10:22 AM
Nyay Re: VBA_Help 06-17-2024, 10:32 AM
kvsrinivasamurthy Re: VBA_Help 06-17-2024, 10:58 AM
6StringJazzer Re: VBA_Help 06-17-2024, 11:15 AM
Nyay Re: VBA_Help 06-17-2024, 11:50 AM
kvsrinivasamurthy Re: VBA_Help 06-17-2024, 12:08 PM
Nyay Re: VBA_Help 06-17-2024, 12:49 PM
Nyay Re: VBA_Help 06-18-2024, 01:40 PM
Nyay Re: VBA_Help 06-19-2024, 09:50 PM
6StringJazzer Re: VBA_Help 06-17-2024, 02:06 PM
Nyay Re: VBA_Help 06-17-2024, 02:19 PM
  1. #1
    Registered User
    Join Date
    06-16-2024
    Location
    Dubai, UAE
    MS-Off Ver
    2019
    Posts
    31

    Re: VBA_Help

    I tried doing that it is still not working. Attaching the file again to with the changes I made as suggested by you.

    ## Code in Sheet 1
    
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.CountLarge > 1 Then Exit Sub
        If Intersect(Target, Range("W2")) Is Nothing Then Exit Sub
    End Sub
    ## Code in Module 1
    
    Sub LinkedToSheet1()
        Dim srcWB As Workbook, desWB As Workbook, desWS As Worksheet, lRow As Long, sPath As String, copyRng As Range
        sPath = ThisWorkbook.Path & "\This_" & "Report_" & Target.Value & ".xlsx"
        If Len(Dir(sPath)) = 0 Then
            MsgBox ("Source file " & sPath & " not found.")
            Exit Sub
        End If
        Set desWB = ThisWorkbook
        Set desWS = desWB.Sheets(1)
        If MsgBox("Do you want to copy all the data from the source workbook or just a selected range?  Click 'Yes' for all data or 'No' to select a range.", vbYesNo) = vbYes Then
            Application.ScreenUpdating = False
            desWS.UsedRange.Offset(1).ClearContents
            Set srcWB = Workbooks.Open(sPath)
            With Sheets(1)
                lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                If lRow > 1 Then
                    .UsedRange.Offset(1).Copy desWS.Range("A2")
                    MsgBox ("Data appended from " & sPath & " to " & desWB.Name)
                Else
                    MsgBox ("No data found in " & sPath)
                End If
            End With
            srcWB.Close False
            Application.ScreenUpdating = True
        Else
            Application.ScreenUpdating = False
            Set srcWB = Workbooks.Open(sPath)
            Application.ScreenUpdating = True
            Set copyRng = Application.InputBox(Prompt:="Select a range to copy.", Title:="Range Selection", Type:=8)
            Application.ScreenUpdating = False
            copyRng.Copy
            desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial
            srcWB.Close False
            Application.ScreenUpdating = True
        End If
    End Sub
    Attached Files Attached Files
    Last edited by Nyay; 06-16-2024 at 12:33 PM.

  2. #2
    Registered User
    Join Date
    06-16-2024
    Location
    Dubai, UAE
    MS-Off Ver
    2019
    Posts
    31

    Re: VBA_Help

    Can someone please help me on this,will be really grateful to you. I just need code correction rest everything is working
    Last edited by Nyay; 06-17-2024 at 03:14 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1