CORRECTING THIS CODE TO START AT THE TOP

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
884
Office Version
  1. 365
Platform
  1. Windows
The following code block simply takes the verse, in this case Romans 6:1 and places rows of text above and below the selection.
Code:
Sub get_multi_verse()
Dim c As Range
Dim tx As String
Dim va
Dim nv As Long

nv = 30 'how many verses before & after selected verse should be displayed ----> nv can be changed to any number which determines no. of verses above and below  selected verse

With wkjv.Range("A:A")
    Set c = .FIND(What:=sREF, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not c Is Nothing Then
         If c.Row - nv < 2 Then
            va = .Cells(2).Offset(, 1).Resize(nv * 2 + 1)
         Else
            va = c.Offset(-nv, 1).Resize(nv * 2 + 1) 'va = c.Offset(-nv, 1).Resize(nv * 2 + 1)
         End If

         For Each X In va
            tx = tx & vbLf & X & vbLf
         Next
         
        'text of selected verse + some verses before & after
        TextBox1 = tx

    Else
        MsgBox "Can't find " & sREF
    End If
End With
End Sub
the first image below shows the highlighted verse, Romans 6:1, in the middle of the text. I want to change the code and,
instead of having the selected verse appear right in the middle of 60 rows(30 above, 30 below), I want the selected verse to
appear at the beginning of the selection as in image 2 below. I can't figure out how to change the code to do that correctly
Can someone please help with this ?
Thanks, cr
 

Attachments

  • SELECTED VERSE IS IN THE MIDDLE OF 15 QBOVE AND 15 BELOW.jpg
    SELECTED VERSE IS IN THE MIDDLE OF 15 QBOVE AND 15 BELOW.jpg
    126.2 KB · Views: 10
  • WANT CODE TO MAKE SELECTED VERSE APPEAR FIRST.  .jpg
    WANT CODE TO MAKE SELECTED VERSE APPEAR FIRST. .jpg
    126.1 KB · Views: 11

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
deleted. I should have reviewed code first as it seems it appends at the end.
 
Last edited:
Upvote 0
OK, this inserts at row 1 on the active sheet:
VBA Code:
With ws
   Set rnge = .Range("A10:C10") 'range to be copied
   rnge.Copy
   Rows("1:1").Select
   Selection.Insert Shift:=xlDown
   Application.CutCopyMode = False
End With
Can use this if the sheet is not the active sheet:
VBA Code:
With ws
   Set rnge = .Range("A10:C10") 'range to be copied
   rnge.Copy
   ws.Activate
   ws.Rows("1:1").Select
   Selection.Insert Shift:=xlDown
   Application.CutCopyMode = False
End With
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

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