Sheet Name is Last Cell Value in A Range

Trancell

New Member
Joined
Jan 29, 2018
Messages
3
I have tried looking through the forums to solve this and i know i have done this some way before. What i am trying to do is Activate a sheet to paste to but the sheet name changes. There are several sheets and i am looking to paste cell values that correspond to the sheet name which is the value of the last cell in Column F. I hope this is making sense. Essentially i want the Sheet to look up the last cell in the "Fuel Log" Column F to produce which sheet it is suppose to select. then it would go to that sheet and paste what it is has copied.

Code:
Sub Test()Sheets("Fuel Log").Range("E" & Cells.Rows.Count).End(xlUp).Copy
Sheets(Range("F" & Cells.Rows.Count).End(xlUp)).Range("A" & Cells.Rows.Count).End(xlUp).Offset(1).Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False


End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
try this, I haven't tested it so could be prone to errors but hopefully it will show you a way to do it:
Code:
Sub Test()
Dim shtname As String


lastrow = Cells(Rows.Count, "E").End(xlUp).Row
'pick up data to paste in variant array
inarr = Sheets("Fuel Log").Range("E1:" & lastrow)
lastF = Cells(Rows.Count, "F").End(xlUp).Row
' pick up the sheet name in string variable
shtname = Cells("f" & lastF)
With Worksheets(shtname)
' paste the dat to the output worksheet
 Range("A1:A" & lastrow) = inarr
End With
 
Upvote 0
I am getting an error with this. I have not had much time to play with it though, I am getting an error on the inarr . I will try it more when i get back to the office.

try this, I haven't tested it so could be prone to errors but hopefully it will show you a way to do it:
Code:
Sub Test()
Dim shtname As String


lastrow = Cells(Rows.Count, "E").End(xlUp).Row
'pick up data to paste in variant array
inarr = Sheets("Fuel Log").Range("E1:" & lastrow)
lastF = Cells(Rows.Count, "F").End(xlUp).Row
' pick up the sheet name in string variable
shtname = Cells("f" & lastF)
With Worksheets(shtname)
' paste the dat to the output worksheet
 Range("A1:A" & lastrow) = inarr
End With
 
Upvote 0
My main question to this is the fact at the Range("F" & cells.Rows Count) part of the function the F is returning an error that says needs a list separator but i do not know why. This function works as a stand alone but when nested inside of the other function it doesnt work.
 
Upvote 0
Sorry my fault i got the syntax wrong i

try this:
Code:
Sub Test()Dim shtname As String




lastrow = Cells(Rows.Count, "E").End(xlUp).Row
'pick up data to paste in variant array
inarr = Sheets("Fuel Log").Range("E" & lastrow & ":E" & lastrow)
lastF = Cells(Rows.Count, "F").End(xlUp).Row
' pick up the sheet name in string variable
shtname = Range("F" & lastF & ":F" & lastF)
With Worksheets(shtname)
' paste the dat to the output worksheet
 Range("A1:A" & lastrow) = inarr
End With
 
Upvote 0
2 things with your original code
Code:
Sub Test()
Range("E" & Cells.Rows.Count).End(xlUp).Copy
Sheets(Range("F" & Cells.Rows.Count).End(xlUp)[COLOR=#ff0000].Value[/COLOR]).Range("A" & Cells.Rows.Count).End(xlUp).Offset(1).[COLOR=#ff0000]PasteSpecial[/COLOR] _
   Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub
It's best to include the .value, otherwise the code may be trying to use the range instead. Also that sheet is not the active sheet you cannot use .Select
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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