ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   code question (https://www.excelbanter.com/excel-discussion-misc-queries/194586-code-question.html)

Shu of AZ

code question
 
In the code below, if I wanted to activate any sheet with a name that
included _U.csv, is there a wildcard I can use?

Windows("Bel080607_u.csv").Activate
Range("A:C,E:E,G:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("A2:C350").Select
Selection.Copy
Windows("WiseGuy66.XLT").Activate
Sheets("R1").Select
ActiveWindow.LargeScroll Down:=1
Range("B62").Select
ActiveSheet.Paste
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("DataSorter").Select
Range("A1").Select
End Sub

Shu of AZ

code question
 
and close the sheet once the code is complete.

The reason for the wildcard is that the _u sheets come in different names
every day

"Shu of AZ" wrote:

In the code below, if I wanted to activate any sheet with a name that
included _U.csv, is there a wildcard I can use?

Windows("Bel080607_u.csv").Activate
Range("A:C,E:E,G:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("A2:C350").Select
Selection.Copy
Windows("WiseGuy66.XLT").Activate
Sheets("R1").Select
ActiveWindow.LargeScroll Down:=1
Range("B62").Select
ActiveSheet.Paste
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("DataSorter").Select
Range("A1").Select
End Sub


Dave Peterson

code question
 
Nope.

But you can loop through the workbooks collection:

Dim wkbk as workbook
dim FoundIt as boolean

Foundit = false
for each wkbk in application.workbooks
if lcase(wkbk.name) like lcase("*_U.csv") then
foundit = true
exit for
end if
next wkbk

if foundit = true then
wkbk.activate
else
msgbox "No workbook names match!"
end if



Shu of AZ wrote:

and close the sheet once the code is complete.

The reason for the wildcard is that the _u sheets come in different names
every day

"Shu of AZ" wrote:

In the code below, if I wanted to activate any sheet with a name that
included _U.csv, is there a wildcard I can use?

Windows("Bel080607_u.csv").Activate
Range("A:C,E:E,G:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
Columns("A:A").Select
Selection.Cut
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Range("A2:C350").Select
Selection.Copy
Windows("WiseGuy66.XLT").Activate
Sheets("R1").Select
ActiveWindow.LargeScroll Down:=1
Range("B62").Select
ActiveSheet.Paste
ActiveWindow.ScrollRow = 1
Range("A1").Select
Sheets("DataSorter").Select
Range("A1").Select
End Sub


--

Dave Peterson


All times are GMT +1. The time now is 04:50 AM.

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