Continuously running recorded macro through table

smichael

New Member
Joined
Jul 15, 2011
Messages
38
I have the recorded macro down, but I would like it to run continuously down the column through the range of data and stop at the desired cell instead of having to click the shortcut for every row. Is there a way to do this?
 
Code:
Sub Change2()
'
' Change2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Dim i As Long
Dim lrow As Long

Application.DisplayAlerts = False

lrow = Range("G" & Rows.Count).End(xlUp).Row

For i = 7 To lrow
    Cells(i, "G").Copy
    Cells(i, "K").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "G").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=RC[4]-RC[3]"
    Cells(i, "G").Copy
    Cells(i, "K").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Copy
    Range("G7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "J").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "0"
    Columns("K:K").Delete Shift:=xlToLeft
Next i
Application.DisplayAlerts = True

End Sub
Sorry this took so long, I was out of the office yesterday!

See if this works for you.
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I've edited some of the stuff to make the macro work how I needed it to, but once i protect the sheet it won't work correctly.

Here is my code:
Code:
Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+Shift+x
'
Dim i As Long
Dim lrow As Long
Application.DisplayAlerts = False
lrow = Range("G" & Rows.Count).End(xlUp).Row
For i = 7 To lrow
    Cells(i, "G").Select
    Selection.Copy
    Cells(i, "K").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "G").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "RC[4]-RC[3]"
    Cells(i, "G").Select
    Selection.Copy
    Cells(i, "K").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Copy
    Cells(i, "G").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells(i, "J").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "0"
    Columns("K:K").Select
    Cells(i, "K").Activate
    
Next i
Application.DisplayAlerts = True
End Sub

Any idea how to correct this?
 
Upvote 0
You might need to specify what is allowed while the sheet is protected.

For instance, this macro changes cell values and deletes columns effectively rearranging columns(cells).

What are you trying to preserve by protecting the sheet?
 
Upvote 0
In protecting the sheet, column G is protected, but i allowed the users to edit columns J and K. This is for an inventory sheet, and I don't want others to personally edit the values in the "Quanity on Hand" field (column G). I would like an administrator to be able to run this macro without unprotecting the G column, if that is possible.

Thanks again for all the help!
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top