Recorded macro

G

Gaurav

Hi All,

I have recorded the following macro.

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 8/22/2008 by gaurav.sharma
'

'
ActiveSheet.Unprotect Password:="justme"
Range("H2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
ActiveWindow.ScrollRow = 9963
ActiveWindow.ScrollRow = 9687
ActiveWindow.ScrollRow = 9225
ActiveWindow.ScrollRow = 8395
ActiveWindow.ScrollRow = 7288
ActiveWindow.ScrollRow = 6181
ActiveWindow.ScrollRow = 5074
ActiveWindow.ScrollRow = 3967
ActiveWindow.ScrollRow = 3045
ActiveWindow.ScrollRow = 2215
ActiveWindow.ScrollRow = 1477
ActiveWindow.ScrollRow = 739
ActiveWindow.ScrollRow = 1
Range("E2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("B2").Select
ActiveSheet.Protect Password:="justme"
ActiveWorkbook.Save
End Sub


I want to add to it that if cell B2 is blank...it gives an error saying
"Invalid Data"

Help is appreciated.
Thanks
 
D

Don Guillett

Sub copyh2nextrow()
Range("j2").Value = Range("h2").End(xlDown)
If Range("b2") = "" Then 'what do you want to do
End Sub
 
R

Roger Govier

Hi

The macro recorder includes a lot of extra stuff that is not required.
I have trimmed this out and included your If test at the end.

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 8/22/2008 by gaurav.sharma

ActiveSheet.Unprotect Password:="justme"
Range("H2").Activate
Range("H2", Selection.End(xlDown)).Copy
Range("E2").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("B2").Activate
If Range("B2") = "" Then
MsgBox "Invalid Data"
End If
ActiveSheet.Protect Password:="justme"
ActiveWorkbook.Save
End Sub
 
G

Gaurav

Thanks Roger. That worked.


Roger Govier said:
Hi

The macro recorder includes a lot of extra stuff that is not required.
I have trimmed this out and included your If test at the end.

Sub Macro6()
'
' Macro6 Macro
' Macro recorded 8/22/2008 by gaurav.sharma

ActiveSheet.Unprotect Password:="justme"
Range("H2").Activate
Range("H2", Selection.End(xlDown)).Copy
Range("E2").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Range("B2").Activate
If Range("B2") = "" Then
MsgBox "Invalid Data"
End If
ActiveSheet.Protect Password:="justme"
ActiveWorkbook.Save
End Sub
 
G

Gaurav

Thanks Don.


Don Guillett said:
Sub copyh2nextrow()
Range("j2").Value = Range("h2").End(xlDown)
If Range("b2") = "" Then 'what do you want to do
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top