Excel VBA

K

KorMaverick

I'm very new to VBA and could use a little help. I wrote a macro that
does the following:

First Part:
Unprotects the sheet; then does a file Save As to a specific folder and
then goes to Cell P2.

All is fine except the macro didn't record the password and I have to
type it in everytime. So it's prompting me for the password everytime.

During the file Save As operating, it says such & such file already
exists, do you want to replace? The answer is always going to be YES.
How do i make that happen?

Second Part:

Once Cell P2 is activated, I type in a code (number) for that specific
column. Then I copy that code all the way down. But depending on the
excel file it may have as many as 20 rows or 50 rows. How do you tell
VBA to copy and paste that code as long as there is a value entered in
Column A?

After that operation, I need to do a Data > Sort; then File Save; Exit.
That part I can manage. It's the rest I'm having problems with. Any
help would be appreciated. Thx.
 
B

Bob Phillips

I'm very new to VBA and could use a little help. I wrote a macro that
does the following:

First Part:
Unprotects the sheet; then does a file Save As to a specific folder and
then goes to Cell P2.

All is fine except the macro didn't record the password and I have to
type it in everytime. So it's prompting me for the password everytime.

ActiveSheet.Unprotect password:="abc"
During the file Save As operating, it says such & such file already
exists, do you want to replace? The answer is always going to be YES.
How do i make that happen?

Application.DisplayAlerts = False
'save file
Application.DisplayAlerts = True
Second Part:

Once Cell P2 is activated, I type in a code (number) for that specific
column. Then I copy that code all the way down. But depending on the
excel file it may have as many as 20 rows or 50 rows. How do you tell
VBA to copy and paste that code as long as there is a value entered in
Column A?

Range("P2").Resize(Cells(Rows.Count, "A").End(xlUp).Row - 1).Value = 101
 
Top