VBA Code to Cut & Paste

kipper19

Board Regular
Joined
Apr 12, 2014
Messages
92
Office Version
  1. 365
Platform
  1. Windows
Would anyone know if this is possible, see spreadsheet, I would like to cut the data from a cell that shows the first date, ie B8 and paste into cell C5, similar B13 into C10 etc
 

Attachments

  • racing data.png
    racing data.png
    69.1 KB · Views: 5

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Your data structure looks pretty consistent, assuming this is reliable on a copy of your workbook give this a try.
Note: It assumes you have no formulas in column C. Let me know if that is not the case.

VBA Code:
Sub CopyFirstDate()

    Dim ws As Worksheet
    Dim rng As Range
    Dim arr As Variant
    Dim rowLast As Long, i As Long
   
    Set ws = ActiveSheet        ' Ideally change to = Worksheets("Your_Worksheet_Name")
    With ws
        rowLast = .Range("B" & Rows.Count).End(xlUp).Row
        Set rng = .Range("A4:C" & rowLast)
        arr = rng.Value
    End With

    For i = 1 To UBound(arr)
        If Left(arr(i, 1), 7) = "Starts:" Then
            arr(i - 1, 3) = arr(i + 2, 2)
        End If
    Next i
   
    rng.Columns(3).Value = Application.Index(arr, 0, 3)

End Sub

My Data Set in case anyone else wants to have a go at it is below:

20230107 VBA Copy Field with Offset kipper19.xlsm
ABCD
1
2
3
4RACE18 STARTERS
5WATC - Performance for: FLASH INVADER
6Starts:01st0
7PlaceMeetingDist.Type
88 of 8BLMT 18/12/20231000TRL
96 of 7BLMT 17/07/2023400TRL
10WATC - Performance for: JUST LEROY
11Starts:01st0
12PlaceMeetingDist.Type
1310 of 10BLMT 18/12/20231000TRL
144 of 8BLMT 31/07/20231000TRL
157 of 8BLMT 17/07/2023400TRL
16WATC - Performance for: TERRATIF
17Starts:01st0
18PlaceMeetingDist.Type
192 of 9LARK 27/11/2023950TRL
203 of 8BLMT 29/07/202312002YO SWP
214 of 11PINJ 20/07/20231200MDN
222 of 10BLMT 05/07/202310002YO 0MW
237 of 11LARK 26/06/2023950TRL
244 of 7LARK 23/01/2023950TRL
Data (3)
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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