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

lookup relative sheet name

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

Lookup relative to sheet name

ResolvedVersion 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:

Get to the end of the used range

What

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.