Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Need help to write macro please

Your do not have matching Sub-End Subs. You have one too many Subs. Remove
the line "Sub Macro2()".

"Bob" wrote in message
...
Mudraker
Thanks for the reply.
Tried copying and pasting into (replacing) existing macro and keep getting
problems
This is exactly what I've pasted in

Sub zeros()
'
' zeros Macro
' Macro recorded 5/26/2004 by Bob
'
' Keyboard Shortcut: Ctrl+b
'
Sub Macro2()
Dim Rng As Range
Columns("B:B").NumberFormat = "@"
For Each Rng In Range("b2:b" _
& Range("b" & Rows.Count).End(xlUp).Row)
If Rng.Value < "" Then
Rng.Value = "0000" & Rng.Value
End If
Next Rng
End Sub

It keeps coming back "compile error - expected end sub"
Any suggestions -
Thanks very much


"mudraker " wrote in message
...
Bob


Try these for starts

Both macros replace the existing number in column B with one that has
0000 at the start


Macro1 runs over b2 to b100

Macro2 runs over b2 to last used cell in column B


Sub Macro1()
Dim Rng As Range
Columns("B:B").NumberFormat = "@"
For Each Rng In Range("b2:b100")
If Rng.Value < "" Then
Rng.Value = "0000" & Rng.Value
End If
Next Rng
End Sub



Sub Macro2()
Dim Rng As Range
Columns("B:B").NumberFormat = "@"
For Each Rng In Range("b2:b" _
& Range("b" & Rows.Count).End(xlUp).Row)
If Rng.Value < "" Then
Rng.Value = "0000" & Rng.Value
End If
Next Rng
End Sub


---
Message posted from http://www.ExcelForum.com/





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
How to write a macro JStiehl Excel Discussion (Misc queries) 4 August 11th 08 10:08 PM
Help write Macro nc Excel Discussion (Misc queries) 5 November 17th 05 03:19 PM
How do i write a Macro that does following Gautam New Users to Excel 5 June 30th 05 08:24 AM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
How do I write a macro for... Christopher Anderson Excel Discussion (Misc queries) 1 December 20th 04 05:18 PM


All times are GMT +1. The time now is 01:21 AM.

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

About Us

"It's about Microsoft Excel"