ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   referencing a sheet in VB (https://www.excelbanter.com/excel-programming/290300-referencing-sheet-vbulletin.html)

Mary Agnes

referencing a sheet in VB
 
1) In VB, how do I list all sheet names on one worksheet?

2) In VB, how do I list all sheets that start with a similar name (e.g., QTD) on one worksheet

I'd really appreciate any and all help!!!!

Trevor Shuttleworth

referencing a sheet in VB
 
Mary Agnes

try these for ideas:

Sub ListWorksheets()
Dim ws As Worksheet
Dim i As Long
For Each ws In Worksheets
i = i + 1
Range("A" & i) = ws.Name
Next ws
End Sub

Sub ListWorksheetsQTD()
Dim ws As Worksheet
Dim i As Long
For Each ws In Worksheets
If UCase(Left(ws.Name, 3)) = "QTD" Then
i = i + 1
Range("A" & i) = ws.Name
End If
Next ws
End Sub

Regards

Trevor


"Mary Agnes" wrote in message
...
1) In VB, how do I list all sheet names on one worksheet?

2) In VB, how do I list all sheets that start with a similar name (e.g.,

QTD) on one worksheet?

I'd really appreciate any and all help!!!!




Rob van Gelder[_4_]

referencing a sheet in VB
 
Mary,

Workbooks contain worksheets.

Sub test()
Dim wks As Worksheet, i As Long

i = 1
For Each wks In Worksheets
Sheet1.Cells(i, 1).Value = wks.Name
i = i + 1
Next
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Mary Agnes" wrote in message
...
1) In VB, how do I list all sheet names on one worksheet?

2) In VB, how do I list all sheets that start with a similar name (e.g.,

QTD) on one worksheet?

I'd really appreciate any and all help!!!!




Mary Agnes :)

referencing a sheet in VB
 
Trevor & Rob:
Thanks so much for your help! I was able to combine both solutions into my program and it was EXACTLY what I was looking for.

Can you recommend a good reference book for using VB 6.0?
Thanks,
Mary Agnes :)


All times are GMT +1. The time now is 10:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com