Questions concerning VBA coding
Thanks for your reply.
1. I was wanting to use VBA coding to create the text string, instead of
pulling from K2. This would help if I need to change in the template I won't
have to change the code as well. It is not a big deal, but I wanted to know
if and how to do it in the macro. Sorry for being unclear.
2. I figured out I can put the code in the Module1 under the Personal.XLS
to keep the other file opening (the one with the template that is). But when
I push the button I get an error message. At this line saying the subscript
is out of range.
Set sh = Sheets("Template")
I tried rearanging things and this did not work either (same error, but at
the if statement).
Sub Copy_Template()
If Not Sheets("Template") Is Nothing Then
Dim sh As Worksheet
Set sh = Sheets("Template")
sh.Copy Befo=sh
ActiveSheet.Name = Range("K2").Value
Range("K2").ClearContents
End If
End Sub
"Bob Phillips" wrote:
"Sloth" wrote in message
...
and the code is
Sub Copy_Template()
Sheets("Template").Copy Befo=Sheets("Template")
Sheets("Template (2)").Name = Cells(2, 11)
Range("K2").Select
Selection.ClearContents
End Sub
I am extremely new to VBA coding and created this code by editing a
recorded
macro. I have three questions concerning this macro.
1. How can I include the K2 formula in the coding?
It already does. Cells(2,11) and Range("K2") is K2
2. I created a custom button and added it to the toolbar. If the file is
not open, I want the button to do nothing, or bringup an error message
(something like "This button is unavailible). Is this possible, or
something
equally effective?
Could try this
Sub Copy_Template()
Dim sh as worksheet
Set sh = Sheets("Template")
If Not sh Is Nothing Then
sh .Copy Befo=sh
Activesheet.Name = Range("K2").Value
Range("K2").ClearContents
End If
End Sub
3. For you programers out there, is there anything majorly wrong with
this
macro? In works for now, but I don't want to accidently overwrite, or
delete, anything in the future.
Should be okay now it uses explicit references.
Also, can anyone suggest a good book to learn VBA programming?
John Walkenbach's VBA For Dummies.
|