PC Review


Reply
Thread Tools Rate Thread

Change "With Worksheets" to "Activesheet"

 
 
J.W. Aldridge
Guest
Posts: n/a
 
      23rd Jul 2008
Code works perfectly....

But plan on using this on various sheets.
How do i change this line to "active sheet"?

With Worksheets("sheet 1")



Sub GetFirstFourLetters()
Dim Col As Variant
Dim X As Long
Dim Z As Long
Dim LastRow As Long
With Worksheets("s.07")
For Each Col In Array("A", "B")
LastRow = .Cells(Rows.Count, Col).End(xlUp).Row
For X = 1 To LastRow
For Z = 1 To Len(.Cells(X, Col).Value)
With .Cells(X, Col)
If Mid$(.Value, Z, 1) Like "[A-Za-z]" Then
.Offset(0, 2).Value = Mid$(.Value, Z, 4)
Exit For
End If
End With
Next
Next
Next
End With
End Sub


Thanx
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      23rd Jul 2008
With ActiveSheet
--
Gary''s Student - gsnu200796
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      23rd Jul 2008
You said...

With Worksheets("sheet 1")

but I am guessing you meant...

With Worksheets("s.07")

which is what is in the code. Anyway, change it to this...

With ActiveSheet

ActiveSheet is a automatically tracked object in VB referencing the active
sheet in the workbook.

Rick


"J.W. Aldridge" <(E-Mail Removed)> wrote in message
news:bde02930-d982-4d53-b47b-(E-Mail Removed)...
> Code works perfectly....
>
> But plan on using this on various sheets.
> How do i change this line to "active sheet"?
>
> With Worksheets("sheet 1")
>
>
>
> Sub GetFirstFourLetters()
> Dim Col As Variant
> Dim X As Long
> Dim Z As Long
> Dim LastRow As Long
> With Worksheets("s.07")
> For Each Col In Array("A", "B")
> LastRow = .Cells(Rows.Count, Col).End(xlUp).Row
> For X = 1 To LastRow
> For Z = 1 To Len(.Cells(X, Col).Value)
> With .Cells(X, Col)
> If Mid$(.Value, Z, 1) Like "[A-Za-z]" Then
> .Offset(0, 2).Value = Mid$(.Value, Z, 4)
> Exit For
> End If
> End With
> Next
> Next
> Next
> End With
> End Sub
>
>
> Thanx


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
change "true" and "false" to "availble" and "out of stock" =?Utf-8?B?aW50aGVzdGFuZHM=?= Microsoft Excel Worksheet Functions 2 19th Jul 2007 07:05 PM
What are the reasons for ""ActiveSheet.Paste Link:=True"" failure CAPTGNVR Microsoft Excel Programming 9 7th Jul 2007 09:56 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" =?Utf-8?B?THVj?= Microsoft Excel Programming 2 28th Sep 2005 08:37 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 AM.