lookup relative sheet name

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Lookup relative to sheet name

Lookup relative to sheet name

resolvedResolved · High Priority · Version 2007

Tom has attended:
Excel VBA Intro Intermediate course
Excel Advanced course
Excel VBA Advanced course
Access Introduction course

Lookup relative to sheet name

Hello!

I am writing a module to get excel to use VLOOKUP to get data relative to the name of a current sheet. Please see code. Can you advise why it comes up with an error? (Is it not possible to attach files in questions)?

It is the line shtName = ActiveSheet.Name
that it doesnt like. By the way, other aspects of writing this routine have gone quite well!

Option Explicit

Option Compare Text

Dim intSheetCount As Integer
Dim shtSheet As Worksheet
Dim shtName As String
Dim numRows As Integer

Sub post()

Sheets("FLAT A").Select

For intSheetCount = 1 To 3

shtName = ActiveSheet.Name

numRows = Range("a33").CurrentRegion.Rows.Count

Sheets(intSheetCount + 9).Cells(numRows + 33, 1).Value = Sheets("demands data").Range("a1").Cells(2, 2).Value
Sheets(intSheetCount + 9).Cells(numRows + 33, 2).Value = Sheets("demands data").Range("a1").Cells(3, 2).Value
Sheets(intSheetCount + 9).Cells(numRows + 33, 4).Value = "=VLOOKUP(""shtName"",input,2)"


Next intSheetCount

End Sub

RE: lookup relative to sheet name

Hi Tom

Thanks for your question

It would indeed be handy for me to see the file. Please email it to me at sw@stl-training.co.uk. I will then get beack to you on this thread.

Regards

Stephen

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Adding multiple rows in an Excel 2010 Worksheet

If you want to add more than one row to an Excel Worksheet, drag select the number or rows you want added to the spreadsheet.

Then right click on these selected rows, choose Insert from the menu, and the new rows will be added above the rows you first selected.

View all Excel hints and tips


Server loaded in 0.09 secs.