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
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
956
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
 

Trancell

New Member
Joined
Jan 29, 2018
Messages
3
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
 

Trancell

New Member
Joined
Jan 29, 2018
Messages
3
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.
 

offthelip

Well-known Member
Joined
Dec 23, 2017
Messages
956
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,569
Office Version
365
Platform
Windows
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
 

Forum statistics

Threads
1,078,520
Messages
5,340,931
Members
399,399
Latest member
SravanaSandhya

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top