compare cell values based on named ranges in another worksheet - vba

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: compare cell values based on named ranges in another worksheet - vba

  1. #1
    New Member
    Join Date
    Jan 2018
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default compare cell values based on named ranges in another worksheet - vba

     
    I am using vba to try to see if values in cells from one workbook match the named ranges from another workbook and if they do match then copy paste values from another column in those named ranges. I know they will match. the purpose is just to copy the values over into their designated named range.
    Here is my code below:
    The problem is in this line --> If rng = ws1.Range("NamedRange") Then ws2.Range("D4:D12").Copy

    Dim strFileName As String
    Dim wb1 As Workbook
    Dim ws1 As Worksheet
    Dim wb2 As Workbook
    Dim ws2 As Worksheet
    Dim cell As Range
    Dim rng As Range
    Dim RangeName As String
    Dim CellName As String


    ''Set wb2 = ActiveWorkbook
    ''Set ws2 = wb2.Sheet("Output")
    ''ws2.Range("D1:D12").Copy

    ''Set wb1 = ActiveWorkbook

    strFileName = CreateObject("WScript.Shell").specialfolders("Desktop") & "\BAC GVP - Template_Update_121917.xlsm"

    If Dir(strFileName) <> vbNullString Then
    Set wb1 = Workbooks.Open(strFileName)
    Else
    MsgBox "Sorry, the file does not exist on your Desktop at this time, please drop a copy to your Desktop from server!"
    End If

    ''Set wb2 = ThisWorkbook
    ''Set ws2 = wb2.Sheets("Output")
    ''Set ws1 = wb1.Sheets("RVP Local GAAP")

    ''ws2.Range("D4:D12").Copy
    ''ws1.Range("G13:G21").PasteSpecial xlPasteValues

    ''RangeName = "myData"
    ''CellName = "G11:G83"

    ''Set cell = Worksheets("RVP Local GAAP").Range(CellName)
    ''ThisWorkbook.Names.Add Name:=RangeName, RefersTo:=cell

    ''RangeName = "NamedRange"
    ''CellName = "C4:C12"


    Set wb2 = ThisWorkbook
    Set ws2 = wb2.Sheets("Output")
    Set ws1 = wb1.Sheets("RVP Local GAAP")

    For Each rng In ws2.Range("G13:G21")
    If rng = ws1.Range("NamedRange") Then ws2.Range("D4:D12").Copy
    ws1.Range("G13:G21").PasteSpecial xlPasteValues
    Next rng
    MsgBox "Both Ranges do not have the same data"
    End Sub

  2. #2
    MrExcel MVP
    Moderator
    Joe4's Avatar
    Join Date
    Aug 2002
    Posts
    42,614
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    1 Thread(s)

    Default Re: compare cell values based on named ranges in another worksheet - vba

      
    Is this a real question that you would like answered? If so, you will want to post it in the "Excel Questions" forum.
    You have posted it in the "Test Here" forum, which is just a forum for testing posting skills and options.
    TIPS FOR FINDING EXCEL SOLUTIONS
    1. Use the built-in Help that comes with Excel/Access
    2. Use the Search functionality on this board
    3. A lot of VBA code can be acquired by using the Macro Recorder.

    "Give a man a fish, feed him for a day. Teach a man to fish, feed him for life!"

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com