Copy contents of Col F in last row of Sheet 1 to same location Sheet 2 when text entered in Sheet 1 Col i

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

I need the values in Col F Col G and Col H in the last filled row of sheet 'Training Log' to be copied to the first empty row in Col F Col G and Col I (NOT H) in sheet 'Indoor Bike' only if/when Col I of the last filled row of sheet 'Training Log' contains the text 'Indoor Bike Session'.

For clarity, the tables below both show the value 125 in Col F, 78% in Col G, the value J in Col H and I and the text 'Indoor Bike Session...' in Col I of Training Log.

Training Log
Wed, 29 Sep 2021OTHER12578%JIndoor bike session, 60 mins.
#NUM!

Indoor Bike
Wed, 29 Sep 20211:00:0021.713.5812578%160J

Many thanks!
 
Last edited:
No, data isn't within a table
I don't understand why it is defined at Column F - should it be the start of the row = Column A?
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Then if your 2nd Sheet name is "Indoor Bike" Not "Indoor Bike Session" Try this:
VBA Code:
Sub Test()
Dim Lr1 As Long, Lr2 As Long
Lr1 = Sheets("Training Log").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
Lr2 = Sheets("Indoor Bike").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row + 1

If Trim(Left(Sheets("Training Log").Range("I" & Lr1).Value, 20)) = "Indoor Bike Session" Then
    Sheets("Indoor Bike").Range("F" & Lr2 & ":G" & Lr2).Value = Sheets("Training Log").Range("F" & Lr1 & ":G" & Lr1).Value
    Sheets("Indoor Bike").Range("I" & Lr2).Value = Sheets("Training Log").Range("H" & Lr1).Value
    Sheets("Indoor Bike").Range("A" & Lr2).Value = Sheets("Training Log").Range("A" & Lr1).Value
End If

End Sub
 
Upvote 0
Yes thanks maabadi, I realised that sheet was incorrectly named and renamed it at the start.

I have just run your amended code and still no data is copied.
 
Upvote 0
Are you have at Last row in Column I the Criteria: Indoor Bike Session
if yes, then try this and see what is result
VBA Code:
Sub Test()
Dim Lr1 As Long, Lr2 As Long
Lr1 = Sheets("Training Log").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
Lr2 = Sheets("Indoor Bike").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row + 1

If Trim(Left(Sheets("Training Log").Range("I" & Lr1).Value, 20)) = "Indoor Bike Session" Then
    Sheets("Indoor Bike").Range("F" & Lr2 & ":G" & Lr2).Value = Sheets("Training Log").Range("F" & Lr1 & ":G" & Lr1).Value
    Sheets("Indoor Bike").Range("I" & Lr2).Value = Sheets("Training Log").Range("H" & Lr1).Value
    Sheets("Indoor Bike").Range("A" & Lr2).Value = Sheets("Training Log").Range("A" & Lr1).Value
End If
MsgBox Lr1 & " , " & Lr2 & Vblf & Trim(Left(Sheets("Training Log").Range("I" & Lr1).Value, 20)) & "*"
End Sub
 
Upvote 0
Hi maabadi, just come back from a 3hr 20min run ;)

Yes, Training Log Col I must have "Indoor Bike Session" as first words for the code to run.

I ran the amended code and the msg I got was "8778 , 359 * " (and no data copied)
 
Last edited:
Upvote 0
Then Do you want copy rows 8778? if Not, i think your question is wrong,
I think you want to find last row that Column I on it Start with "Indoor Bike Session"? Is this you want?
 
Upvote 0
Then Do you want copy rows 8778? if Not, i think your question is wrong,
I think you want to find last row that Column I on it Start with "Indoor Bike Session"? Is this you want?
Row 8778 is empty and is the last row that is filled (shaded green), as in my first post. The last row with data is row 8684 (although I am currently filling Row 8685 with data from the run I have just completed).
 
Upvote 0
Edit: my sincere apologies - I have just realised that Col G has a formula in it that I dragged down and wasn't visible. Am I able to keep this formula or does it interfere with the code? I would like to keep it if possible.
 
Upvote 0
Test this and upload Msgbox Result:
VBA Code:
Sub Test2()
Dim Lr1 As Long, Lr2 As Long, Lr3 as Long, Lr4 As Long, Lr5 As Long, Lr6 as Long, Lr7 As Long, Lr8 As Long
Lr1 = Sheets("Training Log").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
Lr2 = Sheets("Training Log").Range("A" & Rows.Count).End(xlup).Row
Lr3 = Sheets("Training Log").Range("A2").End(xldown).Row
Lr4 = Sheets("Training Log").Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row
Lr5 = Sheets("Indoor Bike").Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row + 1
Lr6 = Sheets("Indoor Bike"). .Range("A" & Rows.Count).End(xlup).Row + 1
Lr7 = Sheets("Indoor Bike").Range("A2").End(xldown).Row + 1
Lr8 =  Sheets("Indoor Bike").Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row + 1
MsgBox Lr1 & " , " & Lr2  & " , " & Lr3  & " , " & Lr4 & Vblf & Lr5 & " , " & Lr6  & " , " & Lr7  & " , " & Lr8
End Sub
 
Upvote 0
I deleted the formula in the unused rows before running your amended code.
 

Attachments

  • Screenshot 2021-09-30 165907.png
    Screenshot 2021-09-30 165907.png
    4.3 KB · Views: 6
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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