Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 02-13-2009, 09:28 AM   #1 (permalink)
wicked23's Avatar
 
I know things...

Join Date: Jun 2006

Location: Pennsylvania

Posts: 399

wicked23 is on a distinguished road

Default Excel VBA?

I'm using MS Excel '07 trying to write a macro where when you hit the button it opens to a floder and let's you choose a text file. Then it imports to excel, deletes a few cells, cut's and pastes some more, then i need it to sort. Everything works except the sort. Basically i don't know what to put in the red Quotes below.

Things i've tried:

myfile
*
*.*
*.305
Sheet2
Left it blank
deleted worksheets and put myfile

Any ideas????


Sub repair5()
'
' repair5 Macro
'
' Keyboard Shortcut: Ctrl+m
'
Sheets("Sheet2").Select
ChDir "E:\MODEM\305\305zip"
myfile = Application.GetOpenFilename("files,*.305")
Workbooks.OpenText Filename:=myfile, _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), _
Array(9, 2), Array(10, 2), Array(11, 2), Array(12, 2), Array(13, 2), Array(14, 2), Array(15 _
, 2), Array(16, 2), Array(17, 2), Array(18, 2), Array(19, 2)), TrailingMinusNumbers:= _
True
Selection.ClearContents
Range("A2:C2").Select
Selection.ClearContents
Range("A338").Select
Selection.ClearContents
Range("Q3:S38").Select
Selection.Cut
Range("A3").Select
ActiveSheet.Paste
Columns("A:A").ColumnWidth = 22.57
Columns("B:B").ColumnWidth = 16.57
Range("B3:B38").Select
ActiveWorkbook.Worksheets("").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("").Sort.SortFields.Add Key:=Range("B3"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("").Sort
.SetRange Range("B3:B38")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ChDir "E:\MODEM\305\Repairs"
__________________
"Research is what I'm doing when it looks like I'm not doing anything"

BEER, is it in you?
wicked23 is offline  
Old 02-13-2009, 11:09 AM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: Excel VBA?

ActiveWorkbook.Worksheets(0).Sort.SortFields.Clear

this would reference the first worksheet. all worksheets have a name (string value, default "Sheet1") and a index (number value...int?) associated with them.
office politics is offline  
Old 02-13-2009, 01:37 PM   #3 (permalink)
wicked23's Avatar
 
I know things...

Join Date: Jun 2006

Location: Pennsylvania

Posts: 399

wicked23 is on a distinguished road

Default Re: Excel VBA?

Thanks OP but that did not work either
__________________
"Research is what I'm doing when it looks like I'm not doing anything"

BEER, is it in you?
wicked23 is offline  
Old 02-13-2009, 03:50 PM   #4 (permalink)
office politics's Avatar
 
It's all just 1s and 0s

Join Date: Jan 2004

Location: in the lab

Posts: 4,410

office politics will become famous soon enough

Default Re: Excel VBA?

try worksheets(1)


i thought they were zero based


Worksheets in VBA Coding and in Worksheet Formulas

Quote:
To use in a macro (note use of a single quote within double quotes in first example)
For csht = 1 To ActiveWorkbook.Sheets.Count 'worksheet or sheets
Cells(cRow - 1 + csht, cCol) = "'" & Sheets(csht).Name
Cells(cRow - 1 + csht, cCol + 1) = Sheets(Sheets(csht).Name).Range("A1").Value
Next csht

office politics is offline  
Old 02-16-2009, 01:05 PM   #5 (permalink)
wicked23's Avatar
 
I know things...

Join Date: Jun 2006

Location: Pennsylvania

Posts: 399

wicked23 is on a distinguished road

Default Re: Excel VBA?

1 :-)

That's it. Thank you so much.
__________________
"Research is what I'm doing when it looks like I'm not doing anything"

BEER, is it in you?
wicked23 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Excel 2007 highlights multiple cells biz_kid1 Windows Operating Systems and Software 26 07-05-2009 12:17 PM
microsoft excel 2003 thaingsokheng Windows Operating Systems and Software 12 09-25-2008 10:46 PM
Curiosity with Excel 2000 Vegeeta Windows Operating Systems and Software 2 01-21-2008 09:54 AM
Excel 2007 bug superdave1984 Windows Operating Systems and Software 0 09-26-2007 11:48 AM