View Full Version : Solved: Read Sheet name from a Cell
afzalw
04-14-2013, 10:30 AM
I want to change sheet number 5 to a name of sheet that is written in cell B6 of Sheet(1).
e.g Cell B6 in Sheet(1) has "Data1" written in it.
Thanks
Set rDest = Sheets(5).Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
GarysStudent
04-14-2013, 10:56 AM
Perhaps:
Sub dural()
Sheets(5).Name = Sheets(1).Range("B6").Value
End Sub
afzalw
04-14-2013, 11:20 AM
I actually don't want to change the name, instead the name of sheet(5) is already "Data1" but I want my code to read the name of sheet from cell B6 of Sheet(1). e.g B6 already have the name of sheet "Data1"
sassora
04-14-2013, 12:44 PM
Do you mean the reverse?
Sub dural()
Sheets(1).Range("B6").Value = Sheets(5).Name
End Sub
afzalw
04-14-2013, 02:23 PM
So this was what I originally posted
Set rDest = Sheets(5).Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
Here the sheet number is 5 but I don't want to it to call this sheet by its number instead I want it to call it by its name which is "Data1".
I can replace 5 with "data1" here right!!! and it will work...... but sheet name is not fixed every-time so I want it to call this sheet name from cell A1 of sheet1.
So that every time sheet name written in cell A1 of sheet1 is changed then sheet name here will also change.
This should work, but not working !
Sheetname = ThisWorkbook.Sheets(1).Range("A1")
Set rDest = Sheets("Sheetname").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Thanks
Set rDest = Sheets(Sheets("Sheet1").Range("A1")).Range("B" & Rows.Count.End(xlUp).Offset(1, 0))
afzalw
04-14-2013, 03:12 PM
Set rDest = Sheets(Sheets("Sheet1").Range("A1")).Range("B" & Rows.Count.End(xlUp).Offset(1, 0))
Did not worked I already tried.
Its same as
sheetname = Sheets("Sheet1").Range("A1")
Set rDest = Sheets("sheetname").Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
Sheetname has the name Data1 stored in it but does not work here don't know why!
GarysStudent
04-14-2013, 03:43 PM
Drop the double quotes:
sheetname = Sheets("Sheet1").Range("A1")
Set rDest = Sheets(sheetname).Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
afzalw
04-14-2013, 04:43 PM
Drop the double quotes:
sheetname = Sheets("Sheet1").Range("A1")
Set rDest = Sheets(sheetname).Range("B" & Rows.Count).End(xlUp).Offset(1, 0)
Ok I did try that before it only works when your sheet name is alphanumeric sometimes my sheet names are only numeric..
e.g
its working for Data1 but If my sheet name is 123 then it wont work
sometimes my sheet names are only numeric..
That's nice to know.
sheetname = Sheets("Sheet1").Range("A1").Text
afzalw
04-14-2013, 05:10 PM
That's nice to know.
sheetname = Sheets("Sheet1").Range("A1").Text
It didn't worked before :banghead: and its working now :dunno.
Thanks:thumb
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.