Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using xl MID function through VB.

Hi,

I have a list in column C.

In column J i'm using xl mid function to calculate a middle value in
column C.


Column C:
89111000111112
89111000111113
89111000111114
89111000111115
89111000111116
89111000111117
89111000111118

Column J: (using xl mid function)
001
001
001
001
001
001
001

The formula is dragged in column J to the last value in column C to
have the result.
I would like to have this formula in VB to claculate the same so that
there would be no need to drag the formula each time column C values
are changed.


Thx.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Using xl MID function through VB.

Hi Sinner

The code below would be one way to do it, though it will all depend on
if your numbers in column C being the same length. Also i added an
apostrophe to the start of the value in column J to stop it from
changing to show "1" and dropping the leading 00. This can be removed
from the code by deleting "'" & from the code.

Paste this code into the module for the sheet you want the code to
run.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 Then

Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)

End If

End Sub

Hope this helps

Steve
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using xl MID function through VB.

Hi Steve,

J1 also changed : ). The values start 2nd row in column C i.e. C2 so
it should start from J2. First one is header.

Thx.


On Feb 21, 5:49*pm, Incidental wrote:
Hi Sinner

The code below would be one way to do it, though it will all depend on
if your numbers in column C being the same length. *Also i added an
apostrophe to the start of the value in column J to stop it from
changing to show "1" and dropping the leading 00. *This can be removed
from the code by deleting "'" & from the code.

Paste this code into the module for the sheet you want the code to
run.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 Then

* * Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)

End If

End Sub

Hope this helps

Steve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using xl MID function through VB.

When I select entire list in column C and clear or paste, it gives a
run-time error. type miss match.
Any idea??

Thx.

On Feb 21, 6:42*pm, Sinner wrote:
Hi Steve,

J1 also changed : ). The values start 2nd row in column C i.e. C2 so
it should start from J2. First one is header.

Thx.

On Feb 21, 5:49*pm, Incidental wrote:



Hi Sinner


The code below would be one way to do it, though it will all depend on
if your numbers in column C being the same length. *Also i added an
apostrophe to the start of the value in column J to stop it from
changing to show "1" and dropping the leading 00. *This can be removed
from the code by deleting "'" & from the code.


Paste this code into the module for the sheet you want the code to
run.


Private Sub Worksheet_Change(ByVal Target As Range)


If Target.Column = 3 Then


* * Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)


End If


End Sub


Hope this helps


Steve- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Using xl MID function through VB.

Hi Sinner

Sorry i should have thought, this should keep it right

If Target.Count = 1 Then

If Target.Column = 3 Then

If Target.Row < 1 Then

Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)

End If

End If

End If

Steve



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using xl MID function through VB.

Steve when I select more than one cell and press delete, the contents
in C are cleared but values in J don't seem to disappear.
Any idea?


Thx.

On Feb 21, 7:47*pm, Incidental wrote:
Hi Sinner

Sorry i should have thought, this should keep it right

If Target.Count = 1 Then

* * If Target.Column = 3 Then

* * * * If Target.Row < 1 Then

* * * * Cells(Target.Row, 10).Value = "'" & Mid(Target.Value, 7, 3)

* * * * End If

* * End If

End If

Steve


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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
User Function Question: Collect Condition in Dialog Box - But How toInsert into Function Equation? SteveM Excel Programming 1 January 3rd 08 03:45 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Excel - User Defined Function Error: This function takes no argume BruceInCalgary Excel Programming 3 August 23rd 06 08:53 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"