+ Reply to Thread
Results 1 to 5 of 5

Passing Reference as new Cell Value

Hybrid View

ExcelWizards Passing Reference as new Cell... 03-20-2013, 03:42 PM
hafizimran Re: Passing Reference as new... 03-20-2013, 04:27 PM
ExcelWizards Re: Passing Reference as new... 03-20-2013, 04:39 PM
hafizimran Re: Passing Reference as new... 03-21-2013, 06:22 AM
ExcelWizards Re: Passing Reference as new... 03-21-2013, 12:17 PM
  1. #1
    Registered User
    Join Date
    01-30-2013
    Location
    Kansas
    MS-Off Ver
    Excel 2007
    Posts
    30

    Passing Reference as new Cell Value

    Okay so my macro copies a row, goes to the sheet where the row will be pasted, finds the the first open row and pastes it there.
    If the number in the 4th column is 0 I want it to instead of copying over the 0 to set Cells(new.Row, 4) to be a reference to where I column 4 of where I copied it.

    I'm not sure how to use the Indirect function inside a macro? Please help.
    If I have assisted you, please add to my Rep

  2. #2
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Passing Reference as new Cell Value

    Please post your code so that it might be edited.

  3. #3
    Registered User
    Join Date
    01-30-2013
    Location
    Kansas
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Passing Reference as new Cell Value

    newst = "= ('" & thesheet.name & "'!D" & therow & ")"

    Is coming out perfect except: therow has apostrophe's around it =('Rightsheet'!'D19')

    My code wasn't the problem it was the concept. There is some code for you, please help.

    This is what I'm using, it could be the wrong function, yes?

    Cells(space, 4).FormulaR1C1 = newst
    Last edited by ExcelWizards; 03-21-2013 at 12:15 PM. Reason: More Code

  4. #4
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Passing Reference as new Cell Value

    Sub CopyPaste()
        Dim strAddress As String    'for storing the source rows 4th cell address
        Dim tr As Long  'for storing the target sheets' last row number
        'Change the sheet name and row number that is being copied
        strAddress = Sheets("Sheet1").Rows("2").Range("D1").Address
        
        'I suppose that your target sheet is Sheet2
        tr = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row + 1
        
        Sheets("Sheet1").Rows("2").Copy
        Sheets("Sheet2").Cells(tr, 1).PasteSpecial
        Application.CutCopyMode = False
        'After pasting
        If Sheets("Sheet2").Range("D" & tr).Value = 0 Then
            Sheets("Sheet2").Range("D" & tr).Formula = "=Sheet1!" & strAddress
        End If
    End Sub

  5. #5
    Registered User
    Join Date
    01-30-2013
    Location
    Kansas
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Passing Reference as new Cell Value

    YES! I meant to use Formula, FormularR1C1 was what was messing it up!

+ 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