Help with macro

E

Esrei

This is the macro I recorded and copied from replies I
got to make up one lager macro.

At:

Dim RowNdx As Long
Dim Last Row as Long

I got stuck, the debugger messages is:
"Duplicate declaration in current scope"

I have never written macro's only recorded them so I only
starting to understand what I am reading.

This is the whole macro:

Pasteldata Macro
' Macro recorded 26/04/2004 by Esrei A Engelbrecht
'

'
Range("B3:B1000").Select
Selection.Copy
Sheets("Pastel STinv").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel GLinv").Select
Range("A2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("C3:C1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel STinv").Select
Range("J2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("E3:E1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel STinv").Select
Range("K2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("F3:F999").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel GLinv").Select
Range("K2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("J3:J1066").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel STinv").Select
Range("F2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("K3:K1000").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel STinv").Select
Range("C2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("Pastel").Select
Application.Goto Reference:="R3C2"
Range("N3:N1086").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Pastel GLinv").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Copy
Range("D2").Select
ActiveSheet.Paste
Range("E2").Select
ActiveSheet.Paste
End Sub
Sub Pasteldata2()
'
' Pasteldata2 Macro
' Macro recorded 26/04/2004 by Esrei A Engelbrecht
'

'
Range("A2:N1039").Select
Selection.Copy
Sheets("Pastel GLinv").Select
Application.Goto Reference:="R1000C1"
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.Goto Reference:="R3C1"
ActiveWindow.SmallScroll Down:=-15
Range("A2:O2038").Select
Application.CutCopyMode = False
Selection.SORT Key1:=Range("A2"),
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
Dim LastRow As Long
Dim row_index As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For row_index = LastRow - 1 To 2 Step -1
If Cells(row_index, "A").Value <> _
Cells(row_index + 1, "A").Value Then
Cells(row_index + 1, "A").EntireRow.insert _
(xlShiftDown)
Rows(1).Copy Destination:=Rows(row_index + 1)
End If
Next
Application.ScreenUpdating = True
Cells.Select
Selection.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("DELIVERIES").Select
Range("A2").Select
Dim RowNdx As Long
Dim LastRow As Long
Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
With Cells(RowNdx, "A")
If .Value <> "Header" And _
.Value <> "" Then
.Value = "Detail"
End If
End With
Next RowNdx
Application.ScreenUpdating = True
End Sub
 
P

Pete McCosh

At:
Dim RowNdx As Long
Dim LastRow as Long
I got stuck, the debugger messages is:
"Duplicate declaration in current scope"

It's telling you that you're trying to create a variable
with the same name as one which is already in existence in
the current macro.

If you take out that second "Dim LastRow as Long" it will
change the value of the existing LastRow variable to your
new condition.

Cheers, Pete.
 
N

Nikos Yannacopoulos

Esrei,

Declaration "Dim LastRow As Long" is repeated twice in your code (do a
search to find). Delete the second one and it's fixed.

HTH,
Nikos
 
D

Dave Peterson

And remove the space between "Last" and "row"

My bet is you want exactly one of these:

dim LastRow as long
 

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