In VBA store the a row ref based on a value entered

markh1182

New Member
Joined
Apr 25, 2006
Messages
48
Hi,

I have this code that runs, and if the If criteria is met, it runs and writes in To Summary. Is it possible to capture the row reference of this cell, so it can be used in a formula, then this repeats?

Code:
Sub Summary()

FinalRow = ActiveSheet.Range("J65536").End(xlUp).Row

    Dim HeadHeight As Double
    Dim tHeight As Double
    Dim n As Long
    HeadHeight = Cells(1, 1).RowHeight
    tHeight = 0
    For n = 1 To ActiveSheet.UsedRange.rows.Count
        tHeight = tHeight + Cells(n, 1).RowHeight
        If tHeight > (752.25 + HeadHeight) Then
 
If Application.WorksheetFunction.Count(rows(n - 1 & ":" & n - 58)) > 0 Then
            
        If Range("J" & n - 1).Value <> "To Summary" Or Range("O" & n).Value <> "" Then
            Range("J" & n - 1).EntireRow.Select
            Selection.Insert Shift:=xlDown
            Range("J" & n - 1).Value = "To Summary"
            tHeight = HeadHeight + Cells(n, 1).RowHeight
        End If
        End If
        End If
    Next n
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
a guess only

dim cfind as range
dim j as integer
set cfind=cells.find (what::="To Summary",lookat:=xlwhole)
j=cfind.row

J will give you the row number
any othere cell in that cell you can use
cells(cfind.row,"D")
that is cfind row and column D.
There are many ways of doing this.

try something on these lines.
 

markh1182

New Member
Joined
Apr 25, 2006
Messages
48
Thanks for that. Looks like it is working and is a good starting point for what I want to achieve.
 

Forum statistics

Threads
1,136,616
Messages
5,676,835
Members
419,653
Latest member
analyticalchemist94

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
Top