0

Is it possible to select a sheet based on the value in the cell. For example

  Col_1      Col_2      Col_3

  gor         100        jan
  mack        60         jan
  john        40         mar---->this data
  ..... So on

Here am checking for persons who have below 50 hours and if they have 50 hours then i have to go to that sheet and mark them to represent them. here john has below 50 hours then i have to get the sheet name from the col_3 that's here March. I have to goto that mar sheet and mark them. My question is that. Is it possible to select or get a sheet name based on the value in a cell.

3
  • 1
    If you know the row/col for that cell then you can use Range(...).Value to get the value in the cell, and yes, use that to activate another sheet, where ... is the cell location, "C4" for example. You can also use Cells(row,col).Value as well.
    – Ryan J
    Commented Mar 16, 2015 at 14:38
  • ws = Worksheets(Worksheets("Report").Range("H" & intRow1).Value).Activate Commented Mar 16, 2015 at 14:48
  • @Ryan J This is what i did so far but returning error cause it is taking only the date eg.. The sheet Name is Mar-15 and that is what is on the cell but it is only getting the data as if in (13/3/15) but there is no sheet named like it. There is only mar-15. And i want it to take as it is. Any suggesion? Commented Mar 16, 2015 at 14:52

3 Answers 3

1

If your cell value is a date string, you can use Format to put it in the string format you require. For example, if your cell contains "3/15/15", you can turn this into the sheet name "Mar-15" using the code below:

Dim dateVal As String
' assume this is your active sheet
Worksheets(1).Activate

' for simplicity, just set a date
Cells(1, 1).Value = "3/15/15"

' read the date from the cell and format to get month name
dateVal = Format(Cells(1, 1).Value, "mmm-YY")
MsgBox ("Month from Date: " & dateVal)

Output shows:

enter image description here

Note that you may need to adjust for the format of your date, as I'm working with a US-English format, but the concept is to format what the value in the cell contains into what you want.

0

About this line ws = Worksheets(Worksheets("Report").Range("H" & intRow1).Value).Activate –

When you want to select or activate any value from particular sheet then those sheet must be activate o/w it gives an error.

0

Try use the below code. It is written for activecell only but can be extended for range of cell.

Dim sname As String

If ActiveCell.Value < 50 Then
    sname = ActiveCell.Offset(0, 1).Value & "-" & "15"
    Sheets(sname).Select

End If

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.