+ Reply to Thread
Results 1 to 2 of 2

VBA pasting formula that changes depending on row

Hybrid View

  1. #1
    Registered User
    Join Date
    04-12-2012
    Location
    Riga
    MS-Off Ver
    Excel 2010
    Posts
    6

    Unhappy VBA pasting formula that changes depending on row

    Hi, I have a long column of data that has blanks within it.
    What I need is to paste formula in all of these blanks that will find the data.

    I have a macro that finds the cells and is ready to execute code:

    Columns("B:B").Select
        Selection.Find(What:="Total:", After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Activate
            
        endRow = ActiveCell.Row - 2
        
        Set rng = Range(Q5, Q99).SpecialCells(xlCellTypeVisible)
        For Each cell In rng
            /CODE HERE
        Next cell
    The formula I`d normally se would something like "=VLOOKUP($G5;'RTG%'!B3:P4253;14;TRUE)" which would work with pasting (The number after "G" needs to change depending on row) but I have no idea how to do in VBA.

  2. #2
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: VBA pasting formula that changes depending on row

    If you can, post an example workbook where one sheet has some sample data and the second sheet has the completed project/information.

    Dim last_Row As Long
    Dim x As Long
    last_Row = Range("A65536").end(xlUp).row
    
    For x = 1 To last_Row
         Range("A" & x).Value = "some_Value"
    Next x
    The above might give you some ideas. It overwrites each value in column A with "some_Value". You could probably change the loop from 1 To last_Row to whatever range you needed.
    Last edited by 111StepsAhead; 04-12-2012 at 09:19 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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