I am looking VBA code, which uses cell value "End" as row number

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Hello,

Here is a code below in which I want to change row number as per cell value find in the column A (Value = End)
First instance in column A "End" row number is 2 so far ABC = Range("B2:E2").Value
Second time in column A "End" row number is 10 so far ABC = Range("B10:E10").Value

And this way keep changing till last row numbers 2, 10, 14, 21, 28 and 36

VBA Code:
Sub EndRowValue()
  
   Dim ABC As Variant
  
   ABC = Range("B2:E2").Value
  
End Sub

*ABCDE
1
2End
3
4
5
6
7
8
9
10End
11
12
13
14End
15
16
17
18
19
20
21End
22
23
24
25
26
27
28End
29
30
31
32
33
34
35
36End

For example the sample image is attached.

Kind Regards
Moti
 

Attachments

  • Row Number.png
    Row Number.png
    9.7 KB · Views: 2

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi, a VBA Range demonstration as a very beginner starter :​
VBA Code:
Sub Demo1()
           Dim Rf As Range, R&, V
    With ActiveSheet.UsedRange.Columns(1)
           Set Rf = .Find("End", , , xlWhole)
        If Not Rf Is Nothing Then
                R = Rf.Row
            Do
                V = [B:E].Rows(Rf.Row).Value2
              ' …
                Set Rf = .FindNext(Rf)
            Loop Until Rf.Row = R
                Set Rf = Nothing
        End If
    End With
End Sub
 
Upvote 0
Solution
Hi, a VBA Range demonstration as a very beginner starter :​
VBA Code:
Sub Demo1()
           Dim Rf As Range, R&, V
    With ActiveSheet.UsedRange.Columns(1)
           Set Rf = .Find("End", , , xlWhole)
        If Not Rf Is Nothing Then
                R = Rf.Row
            Do
                V = [B:E].Rows(Rf.Row).Value2
              ' …
                Set Rf = .FindNext(Rf)
            Loop Until Rf.Row = R
                Set Rf = Nothing
        End If
    End With
End Sub
Marc L, thank you for the reply I tried a lot but do not understand how can I apply in my code so each time find text "End" in my given formula change only the "Row Number"

My formula is ABC = Range("B2:E2").Value, I want when text "End" Find in the column C instead of A than in the formula ("B" & Row number , "E" & Row number) keep changing as per text "End" find in the cell and converted it in to the row number in the VBA Range formula)

Is there any easy solution please suggest

Kind Regards
Moti
 
Upvote 0
Change the column reference - Columns(1) - according to the used range and obviously Rf.Row is the row number …​
Use my codeline rather than your formula …​
 
Upvote 0
Change the column reference - Columns(1) - according to the used range and obviously Rf.Row is the row number …​
Use my codeline rather than your formula …​
Marc L, thank you for the tip and help, now it worked fine

Have a excellent start of the week.

Kind Regards
Moti :)
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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
Back
Top